Jump to content

Archived

This topic is now archived and is closed to further replies.

BreakBreak

Need help with While loops and frames

Recommended Posts

I'm trying to keep a page open and looping for testing purposes of a further project.

I have 4 frames

They are all running while loops with a sleep(1) in them

They 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.

Share this post


Link to post
Share on other sites
Try this:
[code]for($i = 1; $i <= 20; $i++)
{
echo "{$i} seconds\n";
sleep(1);
}[/code]

Share this post


Link to post
Share on other sites
Try this then: [code]while(sleep(1))
{
$i++;
echo "{$i} seconds\n";
}[/code]

Share this post


Link to post
Share on other sites
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 on

Ray

Share this post


Link to post
Share on other sites
This works: [code]<?php
while(1)
{
sleep(1);
$i++;
echo "{$i} seconds\n";
}
?>[/code]

Output (command-line):
[code]daniel@daniel:~$ php /var/www/test.php
1 seconds
2 seconds
3 seconds
4 seconds
5 seconds
6 seconds
7 seconds
8 seconds
9 seconds

daniel@daniel:~$[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.