3

I created an infinite PHP while loop which incremented a variable then echoed:

$num = 1;

while($num >0) {
echo $num . "<br/>";
$num++;
}

I was expecting this to be killed/terminated after 60 seconds as the setting in php.ini are as follows:

max_execution_time  60  60
max_input_time  60  

Sorry if I'm wrong but I expected to see the job killed in the browser (no new echos!)...

Can anyone give me more information on infinite PHP jobs running and when they are actually killed on the server?

5
  • Sleep time does not count against the maximum execution time limit. Are you using sleep() in your loop? Commented Aug 25, 2014 at 20:36
  • No, sorry I just included the loop: Commented Aug 25, 2014 at 20:39
  • Are you editing the correct php.ini file? On ubuntu there is often one in a php folder and another in the apache/php folder. Depending on your environment setup these can change. If you install with pear it could be in a php5 folder. use $ find . -name "php.ini" Commented Aug 25, 2014 at 20:46
  • Hello, the Website is on a shared server. I ran <?php phpinfo(); ?> from httpsdocs and got those settings. Commented Aug 25, 2014 at 20:53
  • You should try to plot the time at each loop execution instead of a number to be sure that what you expect to see as more-than-60-seconds loop is just the time due to network latency, sending the whole buffer to you web browser, etc. Commented Aug 25, 2014 at 20:58

2 Answers 2

1

You are confusing execution time with wall clock time. They are not the same thing. The processor is using very little execution time on each loop of your code. It will eventually time you out but it's going to take a lot longer than a minute.

Think of it this way, your processor may be running at 2GHz. How many instructions do you think it takes to do one of your loops? The time on echo is big (i.e. slow) and it doesn't count toward processor execution time.

Sign up to request clarification or add additional context in comments.

Comments

0
//using set_time_limit 
// starting php code here
echo "starting...\n"; 
// set_time_limit(10); //either would work
ini_set("max_execution_time", 10); //either would work


function doSomeExpensiveWork($currentTime){
  for ($r = 0; $r < 100000; $r++){ 
    $x =  tan(M_LNPI+log(ceil(  date("s")*M_PI*M_LNPI+100))); 
  } 
}

try{
  while(true)
  { 
      $currentTime = date("H:m:s"); 
      echo $currentTime, "\n";
      doSomeExpensiveWork($currentTime);
  } 
} catch (Exception $e) {
  //echo 'Caught exception: ',  $e->getMessage(), "\n";
}
echo "this will not be executed! $x"; 
// code end

2 Comments

Do you think this answer is helping OP to understand, or is it confusing him? Reason for downvote: no explanation
@DanFromGermany this was his question: "Can anyone give me more information on infinite PHP jobs running and when they are actually killed on the server?". before giving a negative vote read the question first. learn to accept others talent. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.