Solved

Close PHP session without saving

Posted on 2009-04-02
6
347 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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