Why should I see runtimes when setting $ _SESSION values?

In my PHP error logs, I see the following errors:

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

Matching lines:

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 

Does it really take 60+ seconds to assign the value of $_SESSION[] ?

Platform:

  • Windows 2003 SP2 + IIS6
  • FastCGI for Windows 2003 (original RTM)
  • PHP 5.2.6 non-potential build

There is no problem clearing the session files on the server after the sessions expire. The oldest sess_XXXXXXXXXXXXXX file that I see is about 2 hours.

There are no explicit timeouts on the disk in event logs or other similar disk problems that can make it difficult to create session data files.

The site is also located on a server that is not under heavy load. The site is busy, but not clogged and very responsive. We just get these errors three or four in a row in a row every three or four hours.

I should also add that I am not the original developer of this code and that it belongs to a client whose developer has long since left.

+4
source share
1 answer

Sessions are blocked. session_start() blocks execution until it can obtain an exclusive lock for this particular session file. This prevents concurrency issues. You can solve this by issuing session_write_close() when you end the session in each script. The reason you see it on the next line is session_start() for blocks> than the maximum execution time. Therefore, when it returns, the next line is executed upon expiration, so where the error occurs.

See session_write_close () for more information.

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

+8
source

Source: https://habr.com/ru/post/1312236/


All Articles