Jump to content


Photo

Maximum Execution Time Exceeded==but WHY?


  • Please log in to reply
4 replies to this topic

#1 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 19 August 2006 - 04:02 AM

Hi All-

I've been racking my brains over this so I though I would show it to the experts. I am building a simple calendar but when I try and preview in my browser I get the following message:
Fatal error: Maximum execution time of 60 seconds exceeded in C:\htdocs\MYSITE\MYFILE.php on line 147

here's what is around line 147 (line 147 is just a } )
  /* Generate the calendar body */
  while ($currentDay <= $noDays) {
        if ($dayOfWeek == 7) {
              $dayOfWeek = 0;
              $calendar .= "</tr><tr>";
        }
$calendar .= "<td>$currentDay</td>";
} // this is line 147
  $currentDay++;
  $dayOfWeek++;

/* Filling in the end of the calendar body */
if ($dayOfWeek != 7) { 
          $remainingDays = 7 - $dayOfWeek;
          $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>"; 
}

Can anyone tell my why I might be having this problem?? Here's the complete function:

          <?php
function build_calendar($month,$year,$day) {
/* Declaring the variables */
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$noDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$dayOfWeek = $dateComponents['wday'];
$monthName = date('F',mktime(0,0,0,$month,1,$year));
/* Computing the previous month. */
if($month == 1) {
$mn=12;
$yn=$year-1;
} else {
$mn=$month-1;
$yn=$year;
}

/* Computing the next month. */
if($month == 12) {
$mn2=1;
$yn2=$year+1;
} else {
$mn2=$month+1;
$yn2=$year;
}

/* Calendar header: next and previous month links */
$calendar = "<table>";
$calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day>&lt;</a></td>";
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
$calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>&gt;</a></td></tr>";
$calendar .="<tr>";

/* Calendar header: Display the days of the week */
foreach($daysOfWeek as $day) {
          $calendar .= "<td>$day</td>";
}
$calendar .= "</tr>";
$calendar .= "<tr>";

  $currentDay = 1;


  /* Fill in the beginning of the calendar body */   
  if ($dayOfWeek > 0) { 
    $calendar .= "<td  colspan='$dayOfWeek'>&nbsp;</td>"; 
  }

  /* Generate the calendar body */
  while ($currentDay <= $noDays) {
        if ($dayOfWeek == 7) {
              $dayOfWeek = 0;
              $calendar .= "</tr><tr>";
        }
$calendar .= "<td>$currentDay</td>";
}
  $currentDay++;
  $dayOfWeek++;

/* Filling in the end of the calendar body */
if ($dayOfWeek != 7) { 
          $remainingDays = 7 - $dayOfWeek;
          $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>"; 
}
 
  $calendar .= "</table>";
return $calendar;
}
if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){
$month = $_GET['m'];
$year = $_GET['y'];
$day = $_GET['d'];
} else {
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
$day = $dateComponents['mday'];
}

echo build_calendar($month,$year,$day);

?>

Any help would be GREATLY APPRECIATED. I'm a newbie so maybe there is something I am not aware of yet. Thanks!

#2 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 19 August 2006 - 04:43 AM

Are you running this off of a shared host? If so, there may be a low execution time, and perhaps your script is taking too long to execute.

Well, I just checked the script on my own server and it is indeed taking too long to load (over 60 seconds). Perhaps you should revise the script to make it so it will not take so long to load.

#3 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 19 August 2006 - 04:47 AM

I did some debugging and the problem lies with your while loop.

<?php
while ($currentDay <= $noDays) {
                 if ($dayOfWeek == 7) {
                     $dayOfWeek = 0;
                     $calendar .= "</tr><tr>";
                 }
                  $calendar .= "<td>$currentDay</td>";
               }
               $currentDay++;
               $dayOfWeek++;
?>

I tried removing the while($currentDay <= $noDays) and the script loaded fine. You may want to revise that (perhaps use an IF statement instead... although I'm not quite sure what you're doing with the script, so I cannot suggest much).

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 19 August 2006 - 01:21 PM

<?php
while ($currentDay <= $noDays) {
                if ($dayOfWeek == 7) {
                    $dayOfWeek = 0;
                    $calendar .= "</tr><tr>";
                }
                  $calendar .= "<td>$currentDay</td>";
              }
              $currentDay++;
              $dayOfWeek++;
?>

The $currentday is incremented OUTSIDE the while loop so you have an infinite loop.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 20 August 2006 - 04:13 AM

Thanks, Barand. I SHOULD have realized that is what was happening. People in this forum rock.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users