this PHP script gets terminated after 60 seconds.
I have already set:
ini_set('max_execution_time', 0);
ini_set('memory_limit','1024M');
And want to execute php using passthru or exec, and have recursive function to check status in db:
function checkstatus() {
$check_status = mysql_fetch_array(mysql_query("select * from table where status='1'",$con));
$status=$check_status["status"];
if ($status !== "1") {
passthru("/usr/bin/php abc.php");
die();
} else {
sleep(30);
checkstatus();
}
}
STOP USING
MYSQL_FUNCTIONS. THEY ARE DEPRECATED AND HAVE BEEN REMOVED FROM MODERN PHP VERSIONS!!Why should I stop?
How do I update my code?
Statusis a MySQL keyword and so should ideally be encapsulated in backticks.Your are only checking the statuses of
where status='1'. Thereforeif ($status !== "1") {will always befalse.Therefore you will always be sleeping for 30 seconds every time this script runs. This is an infinite waste of server resources.
Question Answer:
To stop the time limit being hit, add this code to the top of your script:
However,
Looking at the shape of your script it looks terrible; you do not want to keep PHP hanging on
sleepstatements. Intead you should look into using a PHP Cron Job that executes once every 30 seconds.