我制作这个脚本是为了测试 PHP 作为后台进程的执行情况
foreach($tests as $test) {
exec("php test.php ".$test["id"]);
}
如 php process background 中的建议 和 How to add large number of event notification reminder via Google Calendar API using PHP?和 php execute a background process
但该脚本的运行速度并不比在不添加 test.php 的情况下全部包含在一个脚本中时快。
我做错了什么?
提前致谢!
最佳答案
exec()
将阻塞,直到您正在执行的进程完成 - 换句话说,您基本上是将“test.php”作为子例程运行。至少,您需要在命令行参数中添加一个 &
,这会将 exec() 进程置于后台:
exec("php test.php {$test['id']} &");
关于php在后台执行()函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4646788/