php 后台 exec() 函数
我制作这个脚本是为了测试 PHP 作为后台进程的执行
I made this script to test the execution of PHP as a background process
foreach($tests as $test) {
exec("php test.php ".$test["id"]);
}
如php进程背景中的建议和 如何添加使用 PHP 通过 Google Calendar API 的大量事件通知提醒? 和 php 执行后台过程
但是脚本的运行速度并不比没有添加 test.php 的所有脚本都快.
But the script does not run faster than when it was all in one script without the addition of test.php.
我做错了什么?
提前致谢!
推荐答案
exec()
将阻塞,直到您正在执行的进程完成 - 换句话说,您基本上是在运行您的'test.php' 作为子程序.您至少需要在命令行参数中添加一个 &
,这会将 exec() 进程置于后台:
exec()
will block until the process you're exec'ing has completed - in otherwords, you're basically running your 'test.php' as a subroutine. At bare minimum you need to add a &
to the command line arguments, which would put that exec()'d process into the background:
exec("php test.php {$test['id']} &");
相关文章