![]() |
|
|
|||||||
| Register | iSpy | Wiki | gXboxLive | FAQ | Members List | Social Groups | Calendar | Search | Today's Posts | Mark Forums Read |
| Welcome to the FinalGear.com Forums! | |
| Technology Computers, gadgets and everything else. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
|
|
#1 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
<?php
reset($imena); foreach ($imena as $imja) { echo "something to do here"; } ?> Simple code to work with here, nothing hard for most of you but Im stuck. I need (echo "something to do here" to execute every 5 seconds. I have tried sleep(5); I also tried setting a timer but all these things do is wait some time and then echoing everything at once ![]() Please help, doesnt have to be in php, maybe in java? |
|
|
|
|
|
#2 |
|
"bangle for president"
|
if you want a continuous loop, better use while(true){...}
and in there you can use a sleep method |
|
|
|
|
|
#4 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
<?php
reset($imena); foreach ($imena as $imja) { sleep(5); echo "something to do here"; } ?> I dont remember the timer thing exactly but its with these things: $time_start = microtime(true); $time_end = microtime(true); $time = $time_end - $time_start; so there was another loop that let out only when 5 seconds past which then goes throught the loop again. bone: dont see how different loop will help. |
|
|
|
|
|
#5 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
There is 1 way I managed to make it work:
loop creates as many new windows as needed. Each window has a sleep($n) function with different $n values. When sleep finishes, things are executed. This works but only when I have less than 10 new windows. If I have more, sleep doesnt work very well, probable because it stresses CPU too much. When I mean not very well I mean it should execute something after 80seconds but it executes after 120
|
|
|
|
|
|
#6 |
|
Is it a Windows box? I've found that sleep is really hard on the CPU with Win2003.
__________________
![]() A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them." |
|
|
|
|
|
|
#7 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
Server isnt mine and I have no clue what CPU
|
|
|
|
|
|
#8 |
|
Not the Browser
|
Code:
<?php
$sleeparray[0] = "1";
$sleeparray[1] = "2";
$sleeparray[2] = "3";
$sleeparray[3] = "4";
foreach ($sleeparray as $sleep)
{
echo $sleep . " something to do here
";
sleep(5);
flush();
}
?>
__________________
LFS - Team Finalgear |
|
|
|
|
|
#9 | |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
Quote:
Maybe I should explain what 'something do to': Every 5 seconds the script must open new window of a ganjawars.ru webpage and execute that page. Now everytime a window is open, different details are passed along. The problem is an interval on ganjawars.ru, page there can only be executed once every 5 seconds. |
|
|
|
|
|
|
#10 |
|
Not the Browser
|
^ well I tried without the 'flush()' part and then all the lines showed up at once.
With the flush() its empties the buffer so you see the line, and then sleeps 5 seconds. ect.
__________________
LFS - Team Finalgear |
|
|
|
|
|
#11 | |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
Quote:
|
|
|
|
|
|
|
#12 |
|
Sounds kind of annoying, what you are trying to accomplish....popping up new windows that often.
Why not just use an iframe that refreshes every five seconds? That can be acheived with a client-side javascript or even meta tags. Less stressful on the server and less annoying for the visitor as well.
__________________
![]() A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them." |
|
|
|
|
|
|
#13 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
iframe good, just another way of opening winows kinda. But refreshing isnt going to work here: <form name='gone' action=http://cartman.ganjawars.ru/sms-create.php method=POST target='_blank'><input type=hidden name=outmail value='$SOutmail'><input type=hidden name=mailto value='$SName'><input type=hidden name=subject value='$STitle'><input type=hidden name=msg value='$SText'>
I am posting all this data so everytime its different, refreshing will not work I think. |
|
|
|
|
|
#14 |
|
Well, the page needs to reload in order for your content to change, so the php script will update every 5 seconds. The best way to do this would be to use a meta tag to refresh it. However, it doesn't really matter how it refreshes as long as the script runs again and the content is updated, so you could use a javascript as well.
Try putting this in the head of your php script and if the php variables are dynamic, then they will update when the page refreshes every five seconds: Code:
<meta http-equiv="refresh" content="5;URL=your_script.php">
__________________
![]() A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them." |
|
|
|
|
|
|
#15 |
|
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
![]() ![]() |
I found the easier way:
pausecomp(5000); function pausecomp(millis) { date = new Date(); var curDate = null; do { var curDate = new Date(); } while(curDate-date < millis); } |
|
|
|
|
|
#16 |
|
if you think that's easier, ok
__________________
![]() A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them." |
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
||||||
| Thread Tools | Search this Thread |
|
|