Solved

Close PHP session without saving

Posted on 2009-04-02
6
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
This article discusses how to implement server side field validation and display customized error messages to the client.
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.

737 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