Re: Tight loops and PHP ruining Apache

From: Date: Sun, 06 Aug 2000 15:24:03 +0000
Subject: Re: Tight loops and PHP ruining Apache
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10332@lists.php.net to get a copy of this message
> On SunSITE Denmark, we run a PHP-4.0.x, and we have the problem where > people do too tight loops but accident. Like: > > while($i<numRows($result)) > { > echo $mysql_result($result,$i,"name"); > //Here I forget to increment $i. > } > (Don't tell me to use mysql_fetch_array() (!), this is not my code, but > belongs to the people we host :)) > > This means that the apache runs forever and swallows all the cpu time it > can, and hogs a lot of resources. We run around 150 apache instances at > all time (clones), so this is bound to be a problem sooner or later. > > QUESTION: > Has anybody got a workaround for this "tight-loop" problem? The Max Execution time feature in PHP should be taking care of this for you. I know there were some issues with it during the PHP 4 beta cycle, but it works fine now. For example, I just tried this simple test script on my laptop: <? $a=123; while(1) { for($i=0;$i<10000;$i++) $b = sqrt(sin($a)*cos($a)*tan($a)); echo ".\n"; } ?> Running it resulted in: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fatal error: Maximum execution time of 30 seconds exceeded in /home/rasmus/phpweb/test.php on line 4 So, after 30 seconds of cpu time, the script was killed off. If you need to kill off scripts faster, edit your php.ini file and decrease the value for the max_execution_time directive. -Rasmus

« previous php.general (#10332) next »