开发者

Multiple exec commands php [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

php in background exec() function

I am trying to run two exec commands from PHP. One is a script that might run for a few minutes and there can only be once instance of it. The second exec just checks if the first process is running and either lets you run it again or redirects you. The code is something like this.

This is the main process

$command = '/home/user/active/Nem-Swd.elf 30 > /dev/null 2>&1 & echo $!';

This is the process that checks if the other one is running already.

exec("ps ax | grep $name 2>&1", $output);

I know that in the php API it says :

If a program is started with this function, in o开发者_如何学Gorder for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

But I don't understand what that implies.


It means that if you run the exec command without re-routing its output, your current PHP script will wait for that command to finish before terminating the script. Since you are routing the output to standard out, I believe you should be ok. If you just ran exec($commandJob) you then would run into this problem.


Seems that this question has already been answered:
php in background exec() function

At a minimum (for example) you need to do this to make it run in the background:
exec("php test.php &");


There are other ways to start processes that might be worth looking into as well: http://www.php.net/manual/en/book.pcntl.php
http://php.net/manual/en/function.popen.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜