soma56 Posted July 10, 2010 Share Posted July 10, 2010 Let's say we have a script the does some echoing to the user through a loop. What happens if the users Internet connection goes down? Once it does come back up is there any way to resume or otherwise continue the script from where the user left off? If anyone has a specific page that I can read into this more (if it's even possible) then that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/ Share on other sites More sharing options...
Wolphie Posted July 10, 2010 Share Posted July 10, 2010 You could use sessions. When the user makes the page request you can start the looping process and use a sessions variable to store which iteration the loop is at. If there Internet connection drops, the session variable would stay the same until the user comes back. This is a very very basic way of doing it: <?php session_start(); $start = isset($_SESSION['iteration']) ? $_SESSION['iteration'] : 0; for ($i = $start; $i <= 200000; $i++) { echo $i; $_SESSION['iteration'] = $i; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084115 Share on other sites More sharing options...
soma56 Posted July 10, 2010 Author Share Posted July 10, 2010 Thanks, being new to php > 2 months I've learned a lot and I had a feeling that sessions would be the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084118 Share on other sites More sharing options...
Zane Posted July 10, 2010 Share Posted July 10, 2010 Actually, you might want to use cookies if you're worried about the internet connection going away. Because usually, if the internet connection is gone for a user, you might as well assume they closed their browser too. Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084120 Share on other sites More sharing options...
soma56 Posted July 10, 2010 Author Share Posted July 10, 2010 Well if that's the case let me give you guys a more specific example. Let's assume that the user is receiving mass amounts of data over a couple of hours to their browser but for my purposes we'll use this code: <?php $i = 0; while ($i < 20){ $i++; echo $i; ob_flush(); flush(); usleep (1000000); } ?> Should the connection become lost from the user to the server would it be more wise to use cookies or sessions? Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084180 Share on other sites More sharing options...
Zane Posted July 10, 2010 Share Posted July 10, 2010 Should the connection become lost from the user to the server would it be more wise to use cookies or sessions? Cookies, because they stay on the client's computer; while Sessions stay on the server. They're both pretty much the same thing. Also, It's pretty common to store a Session key into a cookie, which is probably what you're wanting to accomplish.... well, at least I think it's common; it might not be. But, it seems pretty logical. Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084194 Share on other sites More sharing options...
soma56 Posted July 10, 2010 Author Share Posted July 10, 2010 Ok, I'll start mastering cookies now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/207360-what-direction-should-i-take-to-research-this/#findComment-1084250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.