-3

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();  
        }
}
amirali
  • 1,888
  • 1
  • 11
  • 32

1 Answers1

1

enter image description here

STOP USING MYSQL_ FUNCTIONS. THEY ARE DEPRECATED AND HAVE BEEN REMOVED FROM MODERN PHP VERSIONS!!


Status is a MySQL keyword and so should ideally be encapsulated in backticks.


$check_status = mysqli_fetch_array(
                mysqli_query($con,"select * FROM table WHERE `status`='1'")
                );

Your are only checking the statuses of where status='1' . Therefore if ($status !== "1") { will always be false.

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:

set_time_limit(0); // set no limit.

However,

Looking at the shape of your script it looks terrible; you do not want to keep PHP hanging on sleep statements. Intead you should look into using a PHP Cron Job that executes once every 30 seconds.

Martin
  • 22,212
  • 11
  • 70
  • 132