【问题标题】:shell_exec not running in background?shell_exec 不在后台运行?
【发布时间】:2012-05-15 09:43:45
【问题描述】:

我有以下完美执行但不在后台执行的操作?它实际上会停止页面加载,直到完成,这是不好的。

shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &");

我也试过

exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &");

我以为

&

意味着它会执行然后让保持页面继续进行吗?

【问题讨论】:

  • 在我的经验中 exec() 总是需要 0.2 秒来执行。不管你执行什么命令。如果你把 sleep(10);在您的backg.php 文件中,执行原始页面是否需要多花 10 秒?
  • @Sietse 这是执行 backg.php 文件的全部长度......它的行为更像是一个包含而不是应该在后台执行的 exec 脚本跨度>
  • 您可以看看我在此处发布的答案:stackoverflow.com/questions/7703278/… 也许可以提供帮助。

标签: php exec background-process shell-exec


【解决方案1】:
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));

php execute a background process

exec("/usr/bin/php /path/background.php > /dev/null 2>&1 &");

【讨论】:

  • 这是一个非常古老的答案,但在 2021 年的今天,我可以使用不支持 dispatchAfterResponse 的 Apache2 和 mod_php 在后台运行 Laravel 任务(不支持异步运行)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-13
  • 1970-01-01
  • 2012-04-13
  • 1970-01-01
相关资源
最近更新 更多