Answer the question
In order to leave comments, you need to log in
After 60 minutes of recursion, the script stopped. How to prevent?
Test on a dedicated server:
60 minutes of work
0 errors
Test on a hosting:
36 minutes of work
1 error 508 Resource Limit Exceeded
Checking and collecting statistics is done by writing output and output time to the log and constantly reading these logs by JavaScript.
How to prevent the script from stopping (no set_time_limits work on the hosting)?
The recursion itself occurs by pinging itself (self-call).
Sometimes something happens and the ping doesn't work. This is where the recursion stops.
Ignore the 508 error. It's just for statistics.
At what after error 508 the script all the same continues to work. Magic =)
Code:
daemon.php:
<?php
if(date('His')-file_get_contents('./date')<3)
exit; //защита от двойного запуска
file_put_contents('./date', date('His'));
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'); //перезапуск текущей программы
Answer the question
In order to leave comments, you need to log in
30-40 minute PHPs are unstable. You are most likely experiencing memory leaks.
Yes, it would be more logical to make every minute or every five minutes cron - with each new call, the memory will be cleared. In addition, you have protection against calling 2 processes at the same time. Slightly finish so that one process ends another, and it will work fine (for years;)
The wrong time for testing was chosen.
How much is 000100 - 235800?
Certainly less than three. And because of this, your "pseudo-protection" will skip itself, forcing the date to be written to the file.
And the next iteration will get the difference in the script's work in 2 seconds, then in one ...
Here you have a memory leak.
Yes, the removed set_time_limit restrictions do not work on the hosting, they do not work on the server either, I have to remove everything in php.ini. On hosting, they can measure processor time when the limit is exhausted, kill or even block the account.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question