Solved

Close PHP session without saving

Posted on 2009-04-02
6
343 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 500 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
Industry Leaders: 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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

679 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