简体   繁体   English

来自 apache 的 php 脚本中的 nohup 用于长时间运行的进程

[英]nohup from php script served from apache for long running process

Is using exec to run nohup from a php script the right way to go if a long running action needs to run but the web request needs to return right away?如果需要运行长时间运行的操作但需要立即返回 Web 请求,使用exec从 php 脚本运行 nohup 是正确的方法吗? I want to spawn another process from a php script that runs after the request is made.我想从发出请求后运行的 php 脚本生成另一个进程。

Example:例子:

exec ('nohup php long_running_script.php');

//Need this to return happen right away without waiting for long_running_script.php
echo json_encode(array('success' => TRUE));

If at command is available on the hosting, I prefer to use:如果at命令在主机上可用,我更喜欢使用:

putenv( 'SHELL=/bin/sh' );
print `echo /usr/bin/php -q full_path_to_script.php | /usr/bin/at now 2>&1`;

I would check every command's path to be sure that everything is executed correctly:我会检查每个命令的路径以确保一切都正确执行:

echo exec( 'which at' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM