Jump to content

[SOLVED] session_start() takes 10-25 seconds


pnj

Recommended Posts

I'm running a php/mysql database application that stores a database description structure in a session variable.  The database schema is on the large side, so this structure can probably be as big as 500kb.

 

Recently, I've begun having a problem where on some pages, the session_start() function call takes a really long time to return, as long as 25 seconds.  This happens in both a single-user and multi-user environment, but it is inconsistent - on some pages it happens every second or third reload, on some pages it doesn't happen at all.

 

I'm not sure that its related to the size of my structure in a session variable, because the structure has been this big for a long time, but the session_start() problem is relatively new.

 

Does anyone have any suggestions for why this could be taking so long?  Is it a bad idea to store a 500kb structure in a session variable?

 

I really appreciate your help, I am at something of a loss here!

 

-pnj

Link to comment
https://forums.phpfreaks.com/topic/73415-solved-session_start-takes-10-25-seconds/
Share on other sites

No, I am only calling session_start() once in the application, and it is the very first thing I am doing.

 

Ok, I've done some more debugging and identified some more features of the problem.

 

On the problem pages, the 25 second delay happens every second time I reload the page only.  On alternate reloads, the page loads quickly.

 

Further, if instead of reloading the page when the delay is about to happen, if I move to another page in the application, there is the same delay associated with session start.

 

So it sounds like there is something this page is doing with the session that is causing a problem the NEXT time that php tries to retrieve the session.  But it only happens on alternating session retrievals.

 

So does that say anything to anybody?

 

Thanks,

pnj

I'm not sure you got what I was saying.  If you run your script again while your script is already running, then the second run will wait for the first to complete.  It's not about how many times you call session_start() within the one application.

 

Is it possible that the problem pages don't terminate until they reach the timeout, which is 30 seconds by default?

 

Also, do you know if your site is hosted on multiple load-balanced servers or a single server?  session_start()'s locking does not function if the session file is shared over nfs.  This has given me behaviour where I would seemingly randomly get long delays, but other times I would get instant response.

Yes btherl, you are exactly correct.

 

The page had seemingly finished loading, but was making an ajax request to a bad database query that was taking 20-30 seconds to run.  The reloaded page wouldn't begin, I assume, until the database query had finished.

 

I can't explain why it was happening every second time, but maybe it was just coincidence and timing of when i was hitting the refresh key.

 

thanks!  this was a challenging problem as the visible problem was quite far from the code causing the problem.

-pnj

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.