I have an ajax long-polling request that works fine on the first page load. The problem is when the page is reloaded or a new page is browsed to then the PHP session is locked until the old PHP session times out.
I have the following long polling code...
while (time() - $time < 55) {
if ($userid != 0) {
updateUserSession();
fetchMessages();
getTyping();
//getNotifications();
if (!empty($response)) {
header("Content-Type: text/plain");
echo json_encode($response);
exit;
}
}
sleep(2);
}
I have a session_start at the top.
Now, the problem is that the getTyping function might need to set a session, so a session_write_close cannot be called until the long-polling request is done, so I cannot just get the session data and then close it right away.
Can anyone think of a way around this?
Thank you.