Ahmed Wessam Ahmed Wessam - 2 months ago 9
PHP Question

session_start() blocks page load

I have a problem with the function

as it blocks file execution (i.e page loads forever) to even after PHP Max execution time, i thought it was a problem with my code however i cleared all my files and just used this simple script to test and it didn't work

$_SESSION['name'] = "foo";
$name = $_SESSION['name'];
echo "My name is $name";

I'm using WAMP server version 3.0.6 64bit, Apache 2.4.23 - PHP 5.6.25 - MySQL 5.7.14

Answer Source

if you are using file sessions you will need to close writing to the session to prevent multiple PHP requests (that need $_SESSION data) from blocking. example:

// start the session
// I can read/write to session
$_SESSION['latestRequestTime'] = time();
// close the session
// now do my long-running code.

more about the solution