PHP Save Session when using session_write_close();

I've one page where i do a long polling i've to use at the begin of this page this


Because :

to prevent concurrent writes only one script may operate on a session at any time

So if i do not and the long polling is running the user will not be able to load another page.

So accessing to my data in session from this polling page is possible but at some point in my script i've to save my session back to the server because i made some change in it.

What's the way to do it?

That will be very nice it'll be a way to do something like

//do stuff

But the session_write_open() doesn't exist!



Before you make some change to the session, call session_start again. Make the changes, and if you still do not want to exit call session_write_close once more. You can do this as many times as you like.

The previous solution will create a session ids and cookies... I wouldn't use it as is:

Session is created every time you call session_start(). If you want to avoid multiple cookie, write better code. Multiple session_start() especially for the same names in the same script seems like a really bad idea.

see here :

I am looking for a solution right now too and I can't find one. I agree with those who say this is a "bug". You should be able to reopen a php session, but as you said session_write_open() does not exist...

I found a workaround in the above thread. It involves sending a header specifying manually the session id's cookie after processing the request. Luckily enough I am working with a home-brewed Front Controller that works so that no sub-controller will ever send data on its own. In a nutshell, it works perfectly in my case. To use this you might just have to use ob_start() and ob_get_clean(). Here's the magic line:

if (SID) header('Set-Cookie: '.SID.'; path=/', true);

EDIT : see CMCDragonkai's answer below, seems good!?

Need Your Help

How to split a text by a whole line using regex

c# regex

I have a text, something like this:

Pass a fortran derived type which contains allocatable array between different compilers(PGI and Intel)

compiler-construction fortran intel pgi

We have a project which evolves Nvidia GPU and Intel Xeon Phi. The host code and the GPU code is written in Fortran and compiled by pgfortran. To offload some of our job to the Phi, we have to make a