tags:

views:

33

answers:

1

I'm seeing the following errors in my PHP error logs:

PHP Fatal error: Maximum execution time of 60 seconds exceeded in D:\sites\s105504\www\index.php on line 3
PHP Fatal error: Maximum execution time of 60 seconds exceeded in D:\sites\s105504\www\search.php on line 4

The lines in question are:

index.php:

01 <?php
02 session_start();
03 ob_start();
04 error_reporting(E_All);
05 $_SESSION['nav'] = "range";  // <-- Error generated here

search.php

01 <?php
02 
03 session_start();
04 $_SESSION['nav'] = "range";
05 $_SESSION['navselected'] = 21; // <-- Error generated here

Would it really take as long as 60+ seconds to assign a $_SESSION[] value?

The platform is:

  • Windows 2003 SP2 + IIS6
  • FastCGI for Windows 2003 (original RTM build)
  • PHP 5.2.6 Non thread-safe build

There aren't any issues with session data files being cleared up on the server as sessions expire. The oldest sess_XXXXXXXXXXXXXX file I'm seeing is around 2 hours old.

There are no disk timeouts evident in the event logs or other such disk health issues that might suggest difficulty creating session data files.

The site is also on a server that isn't under heavy load. The site is busy but not being hammered and is very responsive. It's just that we get these errors, three or four in a row, every three or four hours.

I should also add that I'm not the original developer of this code and that it belongs to a customer who's developer has long since departed.

+1  A: 

Sessions are blocking. session_start() will block execution until it can get an exclusive lock on that particular session's file. This is to prevent concurrency issues from cropping up. You can solve it by issuing a session_write_close() when you're done with the session in each script. The reason you're seeing it on the next line, is session_start() blocks for > than the max execution time. So when it returns, the next line is executed after the time limit, so that's where the error is raised.

See: session_write_close() for more information

Oh, and based on the errors you posted, the error is generated at the ob_start(); and the $_SESSION['nav'] = "range"; lines respectively, not the line 5 that you indicated in the code section...

ircmaxell
Cheers for the info and thanks for pointing out mistakes.
Kev
Excellent info, totally forgot about this. This can be the culprit only if there is a second request running at the same time, though, and running for a damn long time. Is this indeed the case?
Pekka