问题描述
i有一个脚本(script1)需要调用另一个脚本(script2)。
它不应该等待答案,所以script2应该在后台运行。
我真的需要使用以下方法调用php脚本:
myscript / script2.php
我不想将它用作cgi并使用CLI。
我用fsockopen和curl进行测试,超时10秒并调用
来自浏览器的myscript / script1.php:
Script1在10秒后停止=> OK
Script2已被script1调用并继续在后台运行
=> OK
60秒后Script2被php杀死! => KO :(
如果我打电话给 myscript / script2.php来自
我的浏览器。它需要大约120秒才能完成。
为什么它会在60秒后停止使用fsockopen并从
script1调用它?
以下是SCRIPT1中的脚本:
$ fp = fsockopen(" $ host",80,$ errno,$ errstr,30);
stream_set_timeout($ fp,10);
if(!$ fp){
echo" $ errstr($ errno)< br /> \ n" ;;
} else {
$ out =" GET $ path HTTP / 1.1\r\\\
" ;;
$ out。=" Host:$ host\r\\\
" ;;
$ out。= 连接:关闭\\\\\ nn ;;
fwrite($ fp,$ out);
$ status = socket_get_status($ fp);
while(!feof($ fp)&&!$ status [''timed_out'']){
echo fgets($ fp,128);
$ status = socket_get_status($ fp);
}
fclose($ fp);
}
我在SCRIPT2中添加了这个:
ignore_user_abort(FALSE); // becareful,FALSE真的意味着它应该忽略
用户中止!!!
set_time_limit(120);
ini_set(" max_input_time" ,120);
ini_set(" max_execution_time",120);
你有什么想法吗?
谢谢你的帮助
Rod
Hi,
i have a script (script1) which needs to call another script (script2).
It should not wait for the answer, so script2 should run in the background.
I really need to call the php script using:
http://urlof myscript/script2.php
I don''t want to use it as a cgi and use CLI.
I did a test with fsockopen and curl and a timeout of 10 seconds and call
http://urlof myscript/script1.php from my browser:
Script1 stops after 10 seconds => OK
Script2 has been called by script1 and continue to run in the background
=>OK
After 60 seconds Script2 is killed by php!! => KO :(
The script is working fine if i call http://urlof myscript/script2.php from
my browser. It needs around 120 seconds to finish.
Why is it stopping after 60 seconds when I use fsockopen and call it from
script1?
Here is the script in SCRIPT1:
$fp = fsockopen("$host", 80, $errno, $errstr, 30);
stream_set_timeout($fp,10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$status = socket_get_status($fp);
while (!feof($fp) && !$status[''timed_out'']) {
echo fgets($fp, 128);
$status = socket_get_status($fp);
}
fclose($fp);
}
I have added this in SCRIPT2:
ignore_user_abort(FALSE); // becareful, FALSE really means it should ignore
user abort !!!
set_time_limit (120);
ini_set("max_input_time",120);
ini_set("max_execution_time",120);
Do you have any idea??
Thanks you for your help
Rod
推荐答案
这篇关于使用http在后台运行php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!