New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Process] Process doesn't start if calling script terminates to quickly #7237
Comments
You should check this article
Did you try to setup a callback ? like it's shown in the example ? |
@pborreli I've read that article as well as most of the code for the Process class. As I said in my issue above, I am using the |
@iCode4food are you trying to launch a zombie process ? (and you didn't answered my question, are you using a callback to get feedback) |
I'm developing and deploying on Windows. To add a few more details... I have a long running process that the user will initiate from the website. Instead of having the request wait for several minutes, I want a second process to actually do the work, and the client will ping the server to see if it is done and get status updates. The second, long running process that I'm executing is a Symfony CLI command. |
using a sleep is not bad then, I would do :
|
@pborreli That is exactly what I'm wanting to avoid. I don't want the clien'ts request to wait until the command is done executing, I want it to terminate, send it's output to the client and then ping the server until the long running command is done. |
Apparently I'm not communicating my issue clearly. All that I need to do is allow the child process to continue executing after the parent request is completed. It seems that the parent request ends before the new child process is actually started and thus never starts. If I add |
I think I understand what you're doing @iCode4food ; You're trying to send an HTTP response and run a process while the response has been sent. Actually, this is not recommended to run a process through an URI, it will lead you to some security flaw. It is recommended to use a message queue such as RabbitMQ and some workers to get the job done. If you realy want to implement your design, you have to be sure that you're working with PHP fpm wich provides |
I have the same problem with Process component. The only way i found to do in real background is with nohup (but only on linux):
using symfony command can prevent a little bit for error, but not for infinite loop, and be sure you doesn't have max_execution_time in php.ini (nomally disabled by default for cli). |
thank you very much i managed it to get it works but there's nothing to do with "no hup" in my case. the "../app/console" triggered the process while "app/console" did not. so thanks ! |
@iCode4food I guess you might still be interested for the answer as the problem continues to exist in Process component. I resolved the issue by making a little change in Process class. change updateStatus(false) to updateStatus(true) in start method (https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/Process/Process.php#L301). stream_select will wait for the process to start, thus launching your command. |
Hello @miniyarov , The solution you provide is wrong: If you do this change and run the test suite, you'll see that tests would fail. It seems you expect a blocking Process (a process that does not stop if PHP stops). In this case, you have to use $process->start();
while ($process->isRunning()) {
// do things here
usleep(50000);
} |
Hi. Did you solve this problem? I have now the same behavior, i can run a command with run method, but with start method i got an error: *dots in command are not in real command is just to avoid all parameters here
With run function the command executes fine, so, i don't know what to do. I need the process to run asynchronously because it could be many of them and each can take around 5 mins. |
@jpilldev PHP will kill the subprocess when the main process dies. So even if you start the subprocess asynchronously to be able to keep using the main process while it runs, you should still ensure that your main process does not die before its child process. |
When using Symfony's
IMO, I think the |
@ttk very good point. I think the behavior of symfony/process 2 was to keep things running. As of symfony 3 it's closing when script terminates |
Also adding
|
I am attempting to use the Process component to spaw a second (long running) process. I use ProcessBuilder to create the process, then call
$process->start()
. The process will only actually execute if I make my calling scriptsleep(1)
. If it terminates immediately, the new process will not execute.Is there a way to solve this?
The text was updated successfully, but these errors were encountered: