P
P
PO6OT2015-09-25 23:28:50
PHP
PO6OT, 2015-09-25 23:28:50

After 60 minutes of recursion, the script stopped. How to prevent?

Test on a dedicated server:
60 minutes of work
0 errors
a63b70cd8324418cb8a9f0390fbfb82e.png
Test on a hosting:
36 minutes of work
1 error 508 Resource Limit Exceeded
003062275471403cb8cc304b591060f6.png
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

5 answer(s)
P
Phizio, 2015-09-26
@Phyzio

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;)

D
Denis, 2015-09-26
@prototype_denis

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.

A
Alexander Taratin, 2015-09-26
@Taraflex

Just run the cron script from time to time.

O
Optimus, 2015-09-26
Pyan @marrk2

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.

V
v- death, 2015-11-25
@vGrabko99

Use Go))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question