Php time_sleep_until () and "Mysql server is gone"

I have a script that should be executed every n minutes. n minutes dynamically, so I could not set the cron job to call the script (at a specific time).

so what I did, I saved the time after every n minutes in the array, so when the script is executed, it first checks to see if the current time is in the array. if it is found in the array, it continues to execute, otherwise it will exit.

to execute the script, I have to use the cron job every minute to check the time in the array. Unfortunately, my web host only allows 5 minutes at least. so every time a script is called, I check if the values โ€‹โ€‹between $current_timeand $current_time + (4*60) // 4 minutesin the array are found. if so, and if necessary, I use a time_sleep_untilscript to delay until the time reaches the value found in the array.

so if my script runs at 10:05 and the value found in the array is 10:06, I let the script sleep until 10:06 before it continues to execute. however, if the sleep time is more than a minute or so, I get Mysql server gone away.

how can i prevent this? or is there a better way to do this?

thank!

+3
source share
1 answer

A few options that I donโ€™t know better.

First, make sure your script works with the CLI, and after that minute, it calls it using the http://www.php.net/exec function (if your host allows this).

Two, setting up a script, with a possible hash as a key and using header redirection after the end of a minute, this will call a new script so that a new MySQL connection is created.

, script , , /cron , ( -) , , . , , .

-, , cron, : http://www.onlinecronjobs.com/en

, . , .

+3

Source: https://habr.com/ru/post/1755896/


All Articles