Question

I have tested this script in my localhost a whole day and it's still working. But in cpanel this script is stopped automatically

    set_time_limit(0);
    ini_set('memory_limit', '-1');
    $run = TRUE;
    $nowtime = date("Y-m-d H:i");

    while($run){
        $stop = GetSetting("Stop");
        $time = date("Y-m-d H:i");
        if($stop){
            $run = FALSE; // stopped when setting changed
            continue;
        }
        if($time != $nowtime){
            log_message("debug","Still Running On ".$time); //checking if it still running every minute
        }
        $nowtime = $time;
    }

what do you think happened? What is possible cases that made it stop? Is it about memory? or server configuration? or other possibility?

Était-ce utile?

La solution

You can do this very easily by running PHP from the 'command line'. Here is a sample script to show 'proof of concept'. I run PHP 5.3.18 on windows XP (oi!, stop laffin').

I show the captured output.

Script:

<?php
    // P:\developer\xampp\htdocs\testmysql\Q22710846.php
    //
    // run this from the command line - press ctrl-c to kill the task.

    set_time_limit(0);
    $run = TRUE;
    $nowtime = date("Y-m-d H:i:s");

    $debug = false; // set true to stop after 10
    $loopCount = 10;

    if (!$debug) {
       echo "press ctrl-c to end the task as it will forever!\n\n";
    }
    while(($debug && $loopCount) || (!$debug && $run)) { // will run forever...

        $nowtime = date("Y-m-d H:i:s");
        echo 'The time now is, beep, beep, beep : ', $nowtime, "\n";

        // generate a random delay of between 1 and 10 seconds
        $delay = mt_rand(1, 10);
        echo 'waiting for : ', $delay, " seconds\n";
        sleep($delay);

        // log_message("debug","Still Running On ".$time); //checking if it still running every minute

        if ($debug) {
          $loopCount--;
        }

    }
?>

Sample output...

P:\developer\xampp\htdocs\testmysql>php Q22710846.php
press ctrl-c to end the task as it will forever!

The time now is, beep, beep, beep : 2014-04-02 11:19:03
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:11
waiting for : 7 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:18
waiting for : 6 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:24
waiting for : 6 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:30
waiting for : 5 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:35
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:43
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:51
waiting for : 2 seconds
The time now is, beep, beep, beep : 2014-04-02 11:19:53
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:01
waiting for : 1 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:02
waiting for : 3 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:05
waiting for : 7 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:12
waiting for : 9 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:21
waiting for : 9 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:30
waiting for : 8 seconds
The time now is, beep, beep, beep : 2014-04-02 11:20:38
waiting for : 1 seconds
^C
P:\developer\xampp\htdocs\testmysql>

Autres conseils

it is because of php.ini and php config in your server . you must chang the php time limit by ini_set(); to do this

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top