php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37789 Function Loop, CPU 100%
Submitted: 2006-06-12 16:32 UTC Modified: 2006-06-13 09:33 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: lee dot sargeant dot ls at wbpdata dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.1.4 OS: Windows 2000 Server SP4
Private report: No CVE-ID: None
 [2006-06-12 16:32 UTC] lee dot sargeant dot ls at wbpdata dot com
Description:
------------
6 dates should be outputted when the function in the script is executed. Instead I get a CPU 100% Usage and a fatal error once hitting 60 seconds. I have tried increasing the Memory to allow for a script but it did not work. Also tried on another clean server running a fresh install of PHP 5.1.4

Reproduce code:
---------------
function scheduleWorkingDay($daysback, $day, $month, $year) 
{

//$arr = db_arr("SELECT * FROM issue_days WHERE title_id = $titleid");

$datetotime = strtotime($year.'-'.$month.'-'.$day);

$counter = 1;
$thiscount = 1;

while ( $counter != $daysback ) {

$suffix = $thiscount;
$goback 	= strtotime("-$suffix days", $datetotime);
$dateformat = date("d-m-y",$goback);
$day = date("D",$goback);


if ( $day == "Sat" ) { 
$thiscount++;
//next;

} elseif ( $day == "Sun" ) { 
$thiscount++; 
//next;

} else {
		//print "Got Workday [$day $counter]\n";
		$thiscount++ ;
		$counter++ ;
		//next;
} }
echo $dateformat;

}

Expected result:
----------------
As the function is called in a loop that runs 6 times, 6 dates outputted from the above code.

Actual result:
--------------
PHP causes the server CPU to hit 100% and wille eventually timeout with a fatal error. If the loop runs for less than 6 times, the output is exactly as expected.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-12 16:49 UTC] judas dot iscariote at gmail dot com
Seems you are creating an infinite loop , 100% CPU usage and fatal error after it is the expected behavior.
install xdebug www.xdebug.org it will help you to detect these errors.. looks like there is no bug here.
 [2006-06-12 21:15 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

.
 [2006-06-13 08:17 UTC] lee dot sargeant dot ls at wbpdata dot com
You seem to mis-understand. The function is called in a loop with this code:

$count = 1;
	while($count <= 6) 
			{
				
				//Set Field
				$field = "final".$count;
				//Get date
				scheduleWorkingDay($query2[$field], $_POST['day'], $_POST['month'], $_POST['year']);
				$count++;
			}

If you change the loop to run 5 times instead of 6 as it shows here it will work fine. Anything above 5 and it will not work. 100% CPU Usage as well as the fatal error after the 60 second timeout. I feel there is something wrong, otherwise why would it work with 5 loops ok?
 [2006-06-13 08:39 UTC] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not a support forum.

 [2006-06-13 08:57 UTC] lee dot sargeant dot ls at wbpdata dot com
I do not understand how it can not be a bug. There is a problem with looping a function, clearly???

Thankyou.
 [2006-06-13 09:11 UTC] mgf@php.net
No, the evidence so far points to it being a bug in your function which shows up when $count==6.  Please take this to a support forum and leave the bug as bogus.
 [2006-06-13 09:33 UTC] lee dot sargeant dot ls at wbpdata dot com
Ok, thankyou.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 23 03:00:03 2025 UTC