session_start seems to be very slow (but only sometimes) session_start seems to be very slow (but only sometimes) apache apache

session_start seems to be very slow (but only sometimes)


Have you tried session_write_close(); ?This will disable write-ability in session variables but you can still read data from them. And later when you need to write a session variable, reopen it.

I have also suffered from this problem but this thing worked like a charm. This is what i do:

session_start(); //starts the session$_SESSION['user']="Me";session_write_close();   // close write capabilityecho $_SESSION['user']; // you can still access it


I had the same problem: suddenly the server took 30 seconds to execute a request. I noticed it was because of session_start(). The first request was fast, but each next request took some 30 sec to be executed. I found that the session file in c:\wamp\tmp was locked by the first request for some 30 sec. During this time the second request was waiting for the file to be unlocked. I found out it had something to do with rewrite_mod and .htaccess. I disabled rewrite_mod and commented out every line in .htaccess and it works again like a charm. I don't know why this happend because I don't remember change any settings or conf on wamp.


I ran into this problem too. It was answered here:

Problem with function session_start() (works slowly)

Sessions are locked by PHP while one script is executing, so if scripts are stacked under the same session, they can cause these surprisingly long delays.