PHP - Fire another script into a script without aborting the current one

Asked

Viewed 351 times

1

I have a PHP script that I need "simply shoot" another script however, without losing the current script flow.

Example:

<?php
// um comando
// outro comando
//*** Aqui preciso, por exemplo, disparar o script: teste.php

// outro comando
// outro comando
// outro comando
//*** Aqui preciso novamente disparar o script: teste.php

// outro comando
// outro comando
// outro comando
// outro comando
// fim

(OBS: Servidor compartilhado Locaweb)
?>
  • Use include or require to make sure you’re going to shoot once just use _once example: include_once

  • Cannot be used include or require. The idea is to "shoot" a script in parallel and not include it in the current script.

  • Include this information in the question then, and all other relevant details (for example, what is your concept of "shooting a script"), otherwise staff may waste time answering things that will not suit you.

  • Actually, I’m running a script that runs a long list of tasks. The intention is, at the end of each task, to update a dialogue with written information about the progress (whether each stage was successful or not). This information about the progress, brings to the user, accurate information about what is happening (rather than just a gauge showing the percentage of execution).

  • Colleagues need to pay more attention when a question is SPECIFIC or CONCEPTUAL. Examples: 1) Is it possible to open a text file in PHP? (this is a CONCEPTUAL question (no source code required) -> Just provide some links or snippets of code. 2) My Submit button is not working, what should I do? (this is a specific question and requires the user to display their source code)

  • First of all, the question must be addressed carefully. In my question, I wouldn’t even need to show a pseudo-code, because it’s a CONCEPTUAL question.

  • Yes. But say you want to run another script in parallel is essential. It would be good also to clarify what I meant by "parallel" in the comment.

  • I mentioned this in the code: //*** Here I need to restart the script: test.php Just read.

Show 3 more comments

1 answer

1

If you are running this script in CGI mode(* The Locaweb only allows the execution of these methods in CGI mode), you can use the exec function of php

I couldn’t find anything in Locaweb about the exec function, but I found it on the shell_exec function that serves to execute shell commands:

http://wiki.locaweb.com.br/pt-br/Como_utilizar_a_fun%C3%A7%C3%A3o_PHP_shell_exec()

I don’t know exactly what you want to do but it is worth a reservation if your idea is to perform processing in parallel.

PHP supports threads, so if this is your idea take a look at the doc:

http://php.net/manual/en/intro.pthreads.php

Another option if this runs on the command line and is synchronous, you can subdivide this script into smaller scripts and use redirect via Pipes:

ex: script1.php, script2.php, script3.php

Would run on the command line something like this here:

php script1.php | php script2.php | php script3.php

I hope I’ve helped.

  • Thank you user1030302 for the reply. I see that you understand my question (which is conceptual), in ways that, I do not need to put any specific source code other than the one I displayed at the beginning of the post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.