I know it is possible to create a background PHP process which can be started on demand from another PHP file:
我知道可以创建一个后台PHP进程,可以根据需要从另一个PHP文件启动:
$command = "/usr/bin/php5 -f script.php";
exec( "$command > /dev/null 2>&1 &", $arrOutput);
However this solution works only when PHP is running as mod_php.
但是,此解决方案仅在PHP以mod_php运行时才有效。
Is there any way to do the same on FastCGI?
有没有办法在FastCGI上做同样的事情?
It seems that on FastCGI the process is started and closed again and again by FastCGI, anyone has experience fixing it?
似乎在FastCGI上,这个过程是由FastCGI一次又一次地启动和关闭的,任何人都有修复它的经验吗?
1 个解决方案
#1
0
You could setup a cron job? If not, and it must be called within PHP i have once emulated it in a cross platform way without having access to exec() etc by using curl (believe it or not).
你可以设置一个cron工作?如果没有,并且必须在PHP中调用它,我曾经以跨平台方式模拟它,而无需通过使用curl访问exec()等(信不信由你)。
Create the .php script and make it public, and add this to the top:
创建.php脚本并将其公开,并将其添加到顶部:
if (isset($_POST['key']) == false || $_POST['key'] != 'your secret key') {
die(); //request not allowed
}
then from the other PHP file, create a secure (https) curl connection and POST the secret key to it, set a timeout on curl of say 5 seconds (you can also send a http close connection header from the request page) so that the calling script wont freeze if the request takes to long to complete, in your case 30 seconds.
然后从其他PHP文件创建一个安全(https)卷曲连接并将密钥POST到它,在curl上设置一个5秒的超时(你也可以从请求页面发送一个http关闭连接头),这样就可以了调用脚本不会冻结,如果请求需要很长时间才能完成,在你的情况下为30秒。
This will do the follow: 1. curl will access the page securely (stops just anyway accessing it in their browser) 2. curl will wait 5 seconds, then close the connection (but BOTH your php scripts will carry on)
这将执行以下操作:1。curl将安全地访问页面(无论如何在浏览器中访问它停止)2。curl将等待5秒,然后关闭连接(但是你的php脚本将继续)
It's also compatible regardless of OS internals, shells, etc. You can also tweak the timeouts etc as u see fit.
无论操作系统内部,外壳等,它都兼容。您也可以根据需要调整超时等。
Not a brilliant solution but hope it works well enough for you.
这不是一个出色的解决方案,但希望它能够很好地适合您。
#1
0
You could setup a cron job? If not, and it must be called within PHP i have once emulated it in a cross platform way without having access to exec() etc by using curl (believe it or not).
你可以设置一个cron工作?如果没有,并且必须在PHP中调用它,我曾经以跨平台方式模拟它,而无需通过使用curl访问exec()等(信不信由你)。
Create the .php script and make it public, and add this to the top:
创建.php脚本并将其公开,并将其添加到顶部:
if (isset($_POST['key']) == false || $_POST['key'] != 'your secret key') {
die(); //request not allowed
}
then from the other PHP file, create a secure (https) curl connection and POST the secret key to it, set a timeout on curl of say 5 seconds (you can also send a http close connection header from the request page) so that the calling script wont freeze if the request takes to long to complete, in your case 30 seconds.
然后从其他PHP文件创建一个安全(https)卷曲连接并将密钥POST到它,在curl上设置一个5秒的超时(你也可以从请求页面发送一个http关闭连接头),这样就可以了调用脚本不会冻结,如果请求需要很长时间才能完成,在你的情况下为30秒。
This will do the follow: 1. curl will access the page securely (stops just anyway accessing it in their browser) 2. curl will wait 5 seconds, then close the connection (but BOTH your php scripts will carry on)
这将执行以下操作:1。curl将安全地访问页面(无论如何在浏览器中访问它停止)2。curl将等待5秒,然后关闭连接(但是你的php脚本将继续)
It's also compatible regardless of OS internals, shells, etc. You can also tweak the timeouts etc as u see fit.
无论操作系统内部,外壳等,它都兼容。您也可以根据需要调整超时等。
Not a brilliant solution but hope it works well enough for you.
这不是一个出色的解决方案,但希望它能够很好地适合您。