php在后台exec()函数中

alb*_*ore 3 php process exec

我制作了这个脚本来测试PHP的执行作为后台进程

foreach($tests as $test) { 
   exec("php test.php ".$test["id"]); 
} 
Run Code Online (Sandbox Code Playgroud)

正如php过程背景中提出的 以及如何使用PHP通过Google Calendar API添加大量事件通知提醒?php执行后台进程

但是,如果没有添加test.php,脚本的运行速度就会超过一个脚本.

我究竟做错了什么?

提前致谢!

Mar*_*c B 7

exec()将阻止,直到你执行的过程完成 - 换句话说,你基本上将'test.php'作为子程序运行.至少你需要&在命令行参数中添加一个参数,这会将exec()进程放入后台:

exec("php test.php {$test['id']} &");
Run Code Online (Sandbox Code Playgroud)

  • 根据[手册](http://php.net/manual/en/function.exec.php),它还需要输出重定向才能在后台运行。`php test.php 150 > /dev/null &` (2认同)