FinalGear.com Forums  

Go Back   FinalGear.com Forums > General Discussion > Technology

Welcome to the FinalGear.com Forums!

Technology Computers, gadgets and everything else.

Reply
 
LinkBack Thread Tools Search this Thread
Old August 10th, 2006, 4:48 PM   #1
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default Do every 5 seconds ;)

<?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"images/smilies/wink.gif 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 images/smilies/sad.gif

Please help, doesnt have to be in php, maybe in java?
Xeon SX is offline   Reply With Quote
Want To Remove This Ad? Just Register For A FREE Account!
Old August 10th, 2006, 5:57 PM   #2
"bangle for president"
 
bone's Avatar
 
Joined: Jan 14th, 2004
Last Online: Yesterday
Location: belgium!!
Age: 25
Posts: 6,506
Car: yamaha banshee (and an opel astra from work)
Rep Power: 40
bone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputationbone has between 1000 and 1499 reputation
Send a message via MSN to bone
Default

if you want a continuous loop, better use while(true){...}
and in there you can use a sleep method
bone is offline   Reply With Quote
Old August 10th, 2006, 6:57 PM   #3
.sa = bad driver!
 
chaos386's Avatar
 
Joined: Nov 8th, 2004
Last Online: Yesterday
Location: Al-Khobar, Saudi Arabia
Age: 23
Posts: 4,609
Car: 2009 Seat Leon FR
LFS Status: LFS Status
Rep Power: 144
chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.chaos386 has more bars, in more places.
Playstation Network
Default

Can you post the sleep and timer code you tried as well?
__________________
"Shit, that's a busy table cloth." -matt2000
chaos386 is offline   Reply With Quote
Old August 10th, 2006, 7:35 PM   #4
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

<?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.
Xeon SX is offline   Reply With Quote
Old August 10th, 2006, 7:42 PM   #5
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

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 images/smilies/sad.gif
Xeon SX is offline   Reply With Quote
Old August 10th, 2006, 7:56 PM   #6
 
jeffy777's Avatar
 
Joined: Feb 8th, 2005
Last Online: 7:55 AM
Location: US
Age: 28
Posts: 6,295
Car: '04 Toyota Sienna, crippled people like vans....
Rep Power: 91
jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.
Xbox
Default

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."
jeffy777 is offline   Reply With Quote
Old August 10th, 2006, 8:08 PM   #7
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

Server isnt mine and I have no clue what CPU
Xeon SX is offline   Reply With Quote
Old August 10th, 2006, 8:21 PM   #8
Not the Browser
 
FireFox's Avatar
 
Joined: Feb 7th, 2005
Last Online: November 20th, 2009
Location: Dutchieland
Age: 23
Posts: 1,273
Car: Sold Toyota Carina II. AC Cobra 427 *dream*
LFS Status: LFS Status
Rep Power: 24
FireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputation
Default

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(); 
}
?>
tested on local server, CPU is relaxed.
__________________
LFS - Team Finalgear
FireFox is offline   Reply With Quote
Old August 10th, 2006, 8:35 PM   #9
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

Quote:
Originally Posted by FireFox
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(); 
}
?>
tested on local server, CPU is relaxed.
But thats my main problem, it waits for some time and then does all these thigs at once. I want it to do 1 thing then wiat 5sec and do the other , etc.

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.
Xeon SX is offline   Reply With Quote
Old August 10th, 2006, 8:38 PM   #10
Not the Browser
 
FireFox's Avatar
 
Joined: Feb 7th, 2005
Last Online: November 20th, 2009
Location: Dutchieland
Age: 23
Posts: 1,273
Car: Sold Toyota Carina II. AC Cobra 427 *dream*
LFS Status: LFS Status
Rep Power: 24
FireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputationFireFox has between 250 and 349 reputation
Default

^ 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
FireFox is offline   Reply With Quote
Old August 10th, 2006, 8:52 PM   #11
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

Quote:
Originally Posted by FireFox
^ 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.
I guess it depends on server configurations coz its different here.
Xeon SX is offline   Reply With Quote
Old August 10th, 2006, 9:20 PM   #12
 
jeffy777's Avatar
 
Joined: Feb 8th, 2005
Last Online: 7:55 AM
Location: US
Age: 28
Posts: 6,295
Car: '04 Toyota Sienna, crippled people like vans....
Rep Power: 91
jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.
Xbox
Default

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."
jeffy777 is offline   Reply With Quote
Old August 10th, 2006, 9:52 PM   #13
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

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.
Xeon SX is offline   Reply With Quote
Old August 11th, 2006, 1:41 AM   #14
 
jeffy777's Avatar
 
Joined: Feb 8th, 2005
Last Online: 7:55 AM
Location: US
Age: 28
Posts: 6,295
Car: '04 Toyota Sienna, crippled people like vans....
Rep Power: 91
jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.
Xbox
Default

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."
jeffy777 is offline   Reply With Quote
Old August 11th, 2006, 10:23 AM   #15
 
Xeon SX's Avatar
 
Joined: Feb 8th, 2005
Last Online: 12:24 PM
Location: London
Posts: 1,429
Rep Power: 22
Xeon SX has between 150 and 249 reputationXeon SX has between 150 and 249 reputation
Default

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);
}
Xeon SX is offline   Reply With Quote
Old August 11th, 2006, 5:03 PM   #16
 
jeffy777's Avatar
 
Joined: Feb 8th, 2005
Last Online: 7:55 AM
Location: US
Age: 28
Posts: 6,295
Car: '04 Toyota Sienna, crippled people like vans....
Rep Power: 91
jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.jeffy777 has a reputable reputation.
Xbox
Default

if you think that's easier, ok images/smilies/smile.gif
__________________

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."
jeffy777 is offline   Reply With Quote
Want To Remove This Ad? Just Register For A FREE Account!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Go Back   FinalGear.com Forums > General Discussion > Technology
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 1:16 PM.
All content © FinalGear.com unless stated otherwise.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2
Page generated in 0.20223 seconds with 17 queries by web1
no new posts