session_start() takes VERY LONG TIME

ABTOMAT picture ABTOMAT · Dec 7, 2012 · Viewed 24.8k times · Source

Mys site works very slowly (and I didn't have any idea about why). It is based on Zend Application, I used to make about tens of such sites, so I'm sure that MY code is OK.

I installed xdebugger on server, tried to profile it and guess what? php::session_start() took 48.675 seconds. Fourty Eight and a Half Seconds! It's unbelievable! What could be the reason of this? It's common operation, why could it execute SO long? How to fix such behaviour, which configs to edit? Searched over Google, but found no good answer (almost everywhere there's a question, but no answer). Thanks in before!

xdebugger profiling results

Answer

Christian Davén picture Christian Davén · Mar 7, 2013

session_start (with sessions stored in files) is blocking in PHP, so this issue will appear if you try to start several server sessions for the same browser session (AJAX or multiple browser tabs/windows). Each session_start will wait until the other sessions have been closed.

See here: http://konrness.com/php5/how-to-prevent-blocking-php-requests/

Try changing from files to database storage of sessions.