Need help please with setTimeout for a php include.

Discussion in 'PHP' started by Jen-, Nov 16, 2006.

  1. #1
    Hi, I know sometimes javascript and php can be used together. Anyone know how to add a javascript set timeout to this? So that this php include will re-execute after so much time? Or is there a php refresh command I can add to this code itself, not the page. Thank you very much. Jen


    <?php
    include 'file.php';
    ?>
     
    Jen-, Nov 16, 2006 IP
  2. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well there's the sleep() command, pretty much PHP's equivalent of setTimeout

    http://www.php.net/manual/en/function.sleep.php
     
    crazybjörn, Nov 16, 2006 IP
  3. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    one simple if not elegant way would be to create an iframe on page and have that iframe include a php file. every 5 seconds or whatever it would include a php file. You could control this with sleep.

    ---

    The only problem is that this won't do much good with what displays on the page. A longer approach is necessary to create a real auto updating php script which will actually display itself again on the page. The solution uses ajax and is quite long. Somebody i'll find the time to write out a tutorial for it on my site.

    ---

    Another way would be an auto refresher that just refreshes the page every 5 seconds or so, you could also do that within an iframe to prevent the entire site page from reloading. A problem with this is that in IE you get an annoying click every time you open a new page.
     
    klown, Nov 16, 2006 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    I think that a simple AJAX script to call the php file as whatever interval you need would be the best way to do it.
     
    jestep, Nov 16, 2006 IP
  5. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Refreshing the page won't work, already tried that on a faster timer and it affects the whole page too much, as well as seeing the browser load it at the bottom of the browser each time. If I try it with ajax will that keep the search engines from searching the php?


    I checked out the sleep command and it sounds like it stops the script from executing after so long, when I want it to keep executing. Is there any php command that re-executes the script after so much time?
     
    Jen-, Nov 16, 2006 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    No there is not.

    You need to use Ajax.

    Peace,
     
    Barti1987, Nov 16, 2006 IP