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() 函数


基础教程推荐
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01