PraveenSubramaniyam Posted April 1, 2013 Share Posted April 1, 2013 (edited) 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 April 1, 2013 by Maq Added code tags. Quote Link to comment Share on other sites More sharing options...
PraveenSubramaniyam Posted April 1, 2013 Author Share Posted April 1, 2013 sorry for the post .. Im wrong .. both crashes at the same time .. Nothing diff in the function call_user_func_array() Quote Link to comment Share on other sites More sharing options...
Maq Posted April 1, 2013 Share Posted April 1, 2013 You posted in the wrong section, please be conscious of where you post. Moving to PHP Coding Help. Please use the code tags when posting code. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 1, 2013 Share Posted April 1, 2013 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted April 1, 2013 Share Posted April 1, 2013 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.