Infinite Loading Times When Using PHP Sessions

Posted August 22, 2016 8.5k views
MySQLApachePHPLAMP StackUbuntu 16.04

I have recently started moving from a Sharedhost(HostGator). Hostgator had to much downtime as the website was starting to get a large amount of traffic. I figured this wouldn’t be as painful as it has been. I’ve been working trying to get the server up for almost 3 days with the same result and no luck.

I’m currently working on a project that requires users to login, and when they login or a session have been set by PHP. Everything on the Website will load indefinitely. There doesn’t seem to be a timeout or error codes. It just loads. This project was built when using the Shared Server and has no no problems, everything is stable.

To see the example, Form Inputs(shymus Roffo, password, nexus) Those are all the test values. Once you login, you will need to refresh the page a few times and it will never load. On that example, there were no errors when using shared hosting or any problems. Everything ran very stable.

These were the guides that i followed to get my VPS started. I’m running Ubuntu 16.04.

When i got everything working, when i logged in the website the first time after the LAMP was set up, everything loaded fast. But if i attempted to visit another page after that any page with PHP session_start() would be extremely slow.

There are no errors that appear in the PHP logs or Apache Logs.

Would love to know what might possibly cause this or what could fix it. Would also be great if i could find a way that could pin-point me to finding these errors.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

When checking on your example URL and credentials it does not appear that these issues are still present. Did you find a solution? If so, we’d love it if you can share the details here.

  • Nothing was done to change it. If it’s working fine, then you will need to refresh the page to see the issue. I wish i had fixed it by now.

    When no one has logged in for a while (2-3 hours) then everything will work fine. But once someone logs in, then the issues start. If you log and it’s fine, refresh the page and you will see the never ending loading.

    • That extra information may have been the key. I have seen similar issues before with users on Apache and I’ve got one more thing for you to try. By default apache has a KeepAlive setting that will leave connections open after sending data in order to re-use them. The problem is that apache will only support so many open connections at once so if they are being kept open by the server eventually you run out. When this happens, each request is queued to wait for one of the open ones to reach it’s time-out before it returns the requested page or data. To test this…

      open the file apache2.conf in /etc/apache2/ and edit the KeepAlive line to read:

      KeepAlive Off

      then restart apache with

      service apache2 restart

      Let us know if that solves the problem.

      • I hate to say this, but that doesn’t seem to work. This is the apache2.conf,
        I changed the settings and restarted. However it still seems to act the same.

        One of the things that the dashboard.php script uses, is an event-source. I don’t know if that’s relevant to the issue. But it seemed to work fine on the shared server.