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