session_start seems to be very slow (but only sometimes)

前端 未结 6 1496
暗喜
暗喜 2020-12-05 10:23

For some odd reason, just today our server decided to be very slow during the starting of sessions. For every session_start, the server either times out after 30 seconds, or

相关标签:
6条回答
  • 2020-12-05 10:26

    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 capability
    echo $_SESSION['user']; // you can still access it
    
    0 讨论(0)
  • 2020-12-05 10:26

    Please check if you have correct memcache settings e.g. in /etc/php.d/memcached.ini

    0 讨论(0)
  • 2020-12-05 10:31

    Each session is stored by apache as a text file.

    When session start is use to resume an existing session (via cookie identifier for example) maybe a big session file (a Session with a lot of content inside) can be slow to be started?

    If this is the case probably you application is putting to much data into sessions.

    0 讨论(0)
  • 2020-12-05 10:35

    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.

    0 讨论(0)
  • 2020-12-05 10:38

    I know this is an old question but I've just fixed this issue on my server. All I did was turn on the bypass cache for the domains in the cache manager in the cpanel.

    My sessions were taking ages to start and close now they are instant.

    0 讨论(0)
  • 2020-12-05 10:47

    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.

    0 讨论(0)
提交回复
热议问题