BreakBreak Posted October 16, 2006 Share Posted October 16, 2006 I'm trying to keep a page open and looping for testing purposes of a further project.I have 4 framesThey are all running while loops with a sleep(1) in themThey are all doing the following:$i = 2;$z = 1;while($i > 1){echo "$z second <br>";sleep(1);$z++;}However, for some perculiar reason, three of them stop SOMETIMES after 20 or so seconds, whilst the one to the farthest right carries on.What baffles me is that SOME of them only stop SOMETIMES.Another confusion, once it ran with all four of them counting for over 30 minutes and showed no sign of stopping.PHP is NOT in safe mode.---------Please help me as this is slowing me down hugely and i need to find a solution, fast. Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/ Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 Try this:[code]for($i = 1; $i <= 20; $i++){ echo "{$i} seconds\n"; sleep(1);}[/code] Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109550 Share on other sites More sharing options...
BreakBreak Posted October 16, 2006 Author Share Posted October 16, 2006 Is that not the exact same thing?Note: I want this to be an infinite loop. Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109555 Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 Try this then: [code]while(sleep(1)){ $i++; echo "{$i} seconds\n";}[/code] Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109558 Share on other sites More sharing options...
BreakBreak Posted October 16, 2006 Author Share Posted October 16, 2006 Doesn't work, avoids the loop. Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109581 Share on other sites More sharing options...
craygo Posted October 16, 2006 Share Posted October 16, 2006 try renaming your variables for each frame. Using $i for all frames may be causing problems.$i1 for first frame$i2 for second and so onRay Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109593 Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 This works: [code]<?phpwhile(1){ sleep(1); $i++; echo "{$i} seconds\n";}?>[/code]Output (command-line):[code]daniel@daniel:~$ php /var/www/test.php1 seconds2 seconds3 seconds4 seconds5 seconds6 seconds7 seconds8 seconds9 secondsdaniel@daniel:~$[/code] Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109604 Share on other sites More sharing options...
BreakBreak Posted October 16, 2006 Author Share Posted October 16, 2006 Yes, but (sleep1) didn't.I have changed them to for(;;) loops now and they are working fine, i also got my server to extend the termination time.Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/24099-need-help-with-while-loops-and-frames/#findComment-109644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.