Answer the question
In order to leave comments, you need to log in
How to avoid stopping a self-invoking script?
The script calls itself with ping(), forming an infinite loop, so bypassing runtime limits:
But sometimes the script stops working. Probably the ping () request does not reach or the next script dies while waiting for an exclusive block.
Here is the first option:
daemon.php
<?php
if(date('His')-file_get_contents('./date')<3)
exit;
file_put_contents('./date', date('His'));
$f=fopen('./lock', 'w+');
flock($f, LOCK_EX);
function ping($action){
$h=$_SERVER[HTTP_HOST];
$http=fsockopen($h, 80, $e1, $e2, 1);
if($http){
fwrite($http,
'GET /'.$action.' HTTP/1.1'."\r\n".
'Accept: */*'."\r\n".
'Host: '.$h."\r\n\r\n"
);
fclose($http);
}
}
ping('core.php');
sleep(3);
ping('daemon.php');
usleep(200);
flock($f, LOCK_UN);
daemon.php
<?php
if(date('His')-file_get_contents('./date')<3)
exit;
$f=fopen('./lock', "w+");
flock($f, LOCK_EX);
file_put_contents('./date', date('His'));
include('./lib.inc');
ping('core.php');
sleep(3);
flock($f, LOCK_UN);
usleep(200);
ping('daemon.php');
sleep(2);
if(flock($f, LOCK_EX|LOCK_NB)){
flock($f, LOCK_UN);
sleep(15);
ping('daemon.php');
}
Answer the question
In order to leave comments, you need to log in
Looks like it's running out of allocated memory. See php.ini and measure memory usage.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question