The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 12:25:42 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Pausing for a specified amount of time in php  (Read 3972 times)
schwagman
Rookie
**
Offline Offline

Posts: 26



View Profile
« on: April 24, 2008, 02:46:15 PM »

Lets say you wanted to wait for x seconds in between each line of code before you did something in php, how would 
you approach this in php?
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #1 on: April 24, 2008, 02:58:50 PM »

sleep(10);
would pause for 10 seconds. not sure what the ramifications are of using sleep however.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


View Profile
« Reply #2 on: April 24, 2008, 03:15:15 PM »

AFAIK sleep() doesn't have any bad ramifications.  It merely tells the intreperter to wait (n) before executing the next block of code.

schwagman, there is also the usleep() function, which will stop your operations for micro time.  Depends on what you are trying to get done as to which to use.
Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: April 24, 2008, 03:22:00 PM »

Sleep is actually really really efficient, because your script is for-reals asleep. Like, zero resource usage with the exception of the RAM it sits in. If you're waiting for a server or something, it is very common to sleep(1) then check again because you could have LOADS of processes running with very load processor overhead.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
schwagman
Rookie
**
Offline Offline

Posts: 26



View Profile
« Reply #4 on: April 25, 2008, 12:08:23 PM »

Thanks, fellas.

I tried a google search but didnt know the right words,
nice to have the human element here at the Cache.  Thanks Again.

I considered the old BASIC trick (calculating a certain amount of
time and then doing a useless loop e.g. for i=1 to 10000; $nothing='doesntmatter'; next i)

but realized this could take a different amount of time on different
targets and i didnt want to check the time then loop until the new time.

thanks again! 
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: April 25, 2008, 12:17:37 PM »

I considered the old BASIC trick (calculating a certain amount of
time and then doing a useless loop e.g. for i=1 to 10000; $nothing='doesntmatter'; next i)

but realized this could take a different amount of time on different
targets and i didnt want to check the time then loop until the new time.

but even more important than the net time it takes to wait, this "busy wait" methodology forces the processor to keep dealing with you and is contrary to the *nix way. The OS will halt you and deal with other threads, but because you've outlined an Important Process (a loop) the OS will keep giving you time because it thinks you need it. If you don't need it, don't take it and your processor will be most happy.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #6 on: April 26, 2008, 02:42:18 AM »

I considered the old BASIC trick (calculating a certain amount of
time and then doing a useless loop e.g. for i=1 to 10000; $nothing='doesntmatter'; next i)

Depends how accurate u have to be Wink
Do a get_ticks before and after the sleep and then correct for clock drift Smiley
so if u had to sleep 10 secs but it had to be accurate do like 10 1 sec sleeps and correct
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!