Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Close PHP session without saving

Posted on 2009-04-02
6
Medium Priority
?
355 Views
Last Modified: 2013-12-13
I have a php that will be running for a couple minutes. I need to update a variable in the session and continue processing every 20 seconds or so.

This way I can have another script update a screen on the first scripts progress every 20 seconds or so.

I need to close the session without saving, so not to undo any changes that may take place while the script is processing. Then I need to update and save the session to keep the window that the session is open to a minimal.

How do I close an open session without saving it?

0
Comment
Question by:nbcit
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:MatthewP
ID: 24050429
Im not completely sure I understand, but if you're just reporting on session data and not setting anything, it shouldn't update anyway unless you specifically set someting in it in this script. Your other script should be able to continue uninterrupted whilst the other one reports on it. Why do you need to 'close' the session, can't you just leave it after reporting?

Closing sessions is done with something like session_destroy() - if you dont call this it should be fine?

Matt
0
 

Author Comment

by:nbcit
ID: 24050556
In the long script every itterattion I want to update the progress in the session. I know how many loops to need to complete. Each loop takes 10 seconds or so. And if I have 100 loops I know each time I loop I will be 1% done. As the script progresses I want to update this value, so a second script can update the page on progress.
0
 
LVL 6

Accepted Solution

by:
MatthewP earned 1500 total points
ID: 24050840
Ah I see what you mean now, the session isn't released by the first script so that you can get to it. You're best off every iteration writing the value out to a text file and reading the text file from the other script. So each iteration, do file_put_contents("counter.txt",$value");. Then read it from your other script which refreshes every so long using $filedata=file_get_contents("counter.txt");



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:MatthewP
ID: 24050866
Or you can of course write the data to a database and retrieve it, any method of storing data other than sessions should work I think. a text file with one integer in it will give you the lowest overhead on the server.
0
 

Author Comment

by:nbcit
ID: 24054706
I am thinking the text file will be better than:
            session_write_close();
Start Loop
                  session_start();
Save Stuff
            session_write_close();
End Loop
0
 

Author Comment

by:nbcit
ID: 24098356
Saving a file seemed to do the trick.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question