Jump to content

Recommended Posts

I'm working on a php project . A class file which has function index which has a while loop that runs indefinitely sleeping every 3 sec and printing some information . so I wrote a php script which creates an object of tht class file and runs the class function using call_user_func_array function . But the script crashes every 2.30 hours (approximately) with the error "maximum execution time of 300 secs exceeded " .

so tried a different script which doesnt have a class file and have a while loop sleeping every 3 sec and printing the same information . But this script does not crash at all .. Can some one pls help me on what call_user_func_array does ??

 

 

 

main.php

 

 

 

<?php
set_time_limit(300);
require("/project/DCM/dcm.php");
    $foo = new Dcm();
    call_user_func_array(array($foo, "index"),array());
?>


class Dcm
{
 
  public function wakeup_device()
  {
      for($i=0;$i<1000;$i++)
      {
          print("bfr request :".date("Y-m-d H:i:s:u")."\n");
      print("Time ..$i");
        print("after request :".date("Y-m-d H:i:s:u")."\n");
      }
  }
 
   
  public function index()
  {
    
    while(1)
    {
      
      $this->wakeup_device();
      sleep(3);
    }
  }
}
 

 

 

 

test.php

 

 

 

<?php
set_time_limit(300);
while(1)
{

$i=0;
for($i=0;$i<1000;$i++)
print("\n".date("Y-m-d H:i:s")."test ..$i\n");
sleep(3);
}
?>
 
Edited by Maq
Added code tags.

You've set the time limit of 300. while(1) will cause this script to run INFINITELY. You can set the time to whatever you want, eventually you'll run out of memory.

 

WTF are you trying to do?

sleep() does not count towards execution time so your script will not terminate after five minutes. However both of them will eventually die: the first script has more code and so will die sooner, but your test script will die too if you wait long enough.

 

However you look at it, you told PHP to stop after some amount of time so why are you surprised that PHP is stopping after some amount of time?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.