pnj Posted October 16, 2007 Share Posted October 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
btherl Posted October 16, 2007 Share Posted October 16, 2007 Are you doing multiple requests simultaneously? session_start() will block until any previous request for the same session has completed. Quote Link to comment Share on other sites More sharing options...
pnj Posted October 16, 2007 Author Share Posted October 16, 2007 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 Quote Link to comment Share on other sites More sharing options...
btherl Posted October 16, 2007 Share Posted October 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
pnj Posted October 17, 2007 Author Share Posted October 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.