php in background exec() function(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']} &");
这篇关于php 后台 exec() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php 后台 exec() 函数


- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01