是一次执行一个还是同时执行多个 PHP 脚本 运行?
Is executing multiple PHP Scripts ran one at a time or simultaneously?
当使用 exec
命令在 PHP 中执行多个脚本时;每个脚本 运行 是一个接一个地一个接一个还是同时 运行?
exec('/usr/bin/php -q process-duplicates.php');
exec('/usr/bin/php -q process-images.php');
exec('/usr/bin/php -q process-sitemaps.php');
只是想在尝试重写我的 crontab 之前确保它们是一个接一个。
exec 等待脚本到return,见php.net
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
但是作为一个 devops,请不要 运行 你的 cron 工作是这样的!在 crontab 中为每个条目创建条目,或将它们放入 shell 脚本中并让 cron 运行 脚本。
当然,在后台 运行 的唯一方法是将 & 添加到命令行参数,这会将 exec() 的进程置于后台:
exec("php test.php &");
所以你是对的,他们运行一个接一个
注意: 在您的情况下,您不应使用 &
,因为它会强制同时 运行 所有脚本。
当使用 exec
命令在 PHP 中执行多个脚本时;每个脚本 运行 是一个接一个地一个接一个还是同时 运行?
exec('/usr/bin/php -q process-duplicates.php');
exec('/usr/bin/php -q process-images.php');
exec('/usr/bin/php -q process-sitemaps.php');
只是想在尝试重写我的 crontab 之前确保它们是一个接一个。
exec 等待脚本到return,见php.net
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
但是作为一个 devops,请不要 运行 你的 cron 工作是这样的!在 crontab 中为每个条目创建条目,或将它们放入 shell 脚本中并让 cron 运行 脚本。
当然,在后台 运行 的唯一方法是将 & 添加到命令行参数,这会将 exec() 的进程置于后台:
exec("php test.php &");
所以你是对的,他们运行一个接一个
注意: 在您的情况下,您不应使用 &
,因为它会强制同时 运行 所有脚本。