Solved

Close PHP session without saving

Posted on 2009-04-02
6
335 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 47
Why does my array not "dump?" 5 19
Web Reply Form - PHP with Upload 4 20
Change password through link 1 12
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…
The viewer will learn how to dynamically set the form action using jQuery.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now