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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.