Wait Function

Discussion in 'PHP' started by stupidfly, Jul 20, 2006.

  1. #1
    Is there a way to make a PHP script wait to perform a task? Something like setTimeout() in Javascript, but in PHP.
     
    stupidfly, Jul 20, 2006 IP
  2. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
  3. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Exactly what I was looking for. Thanks.
     
    stupidfly, Jul 21, 2006 IP
  4. aras

    aras Active Member

    Messages:
    533
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #4
    This way, it waits but outputs all of the values at just one time. Is this possible to output partially for example :

    output:

    Registering new user name
    Adding database entry
    (waits here 2 second)
    goes on output.. after 2 second
     
    aras, Jul 22, 2006 IP
  5. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it is a bad idea to use sleep() for delayed output effects as

    1) you have to flush() output before you sleep

    2) depending on your setup flush() will not work all the way to the browser as the web server might apply buffering of its own or the browser might not render output it thinks not to be complete

    netscape for example will only display complete lines and will not show table parts until the </table> tag arrived

    so use sleep if you have to wait for events and don't want to burn to much cycles, but don't use it for silly delayed output effects!
     
    giraph, Jul 22, 2006 IP