#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Simple Timer control


    Hi,

    Does anyone know how I can add a timer to a page so that it
    checks the timestamp of a file every second ? I have the function to check the
    timestamp. The problem is that I can't find a timer control.

    Thanks.
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    A timer "control"? Are you sure you're in the right forum? You're using PHP and not ASP/ASP.NET?

    Doing what you're literally asking for is a bit extreme and quite a bit wasteful. What is the problem you're trying to solve, and for which this timer thing is supposed to help with?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0
    I'm giving online classes and I frequently make a screenshot (with screenhunter) , upload it to my server (with Filezilla) and then cut and paste the link into the Sype message window so my student clicks the link ans sees the picture.
    A bit tiresome to keep doing it every time I show a new picture.
    I want a virtual whiteboard to share. I tried a few but they need Java instgallations ( too technical for some students ) so I prefer the idea of a system where I have a script on my computer that checks for updated screenshot file and ftps it to my server. (runs every second)
    And then a web page that the student has open which includes a script (php?) that checks for updated ftp'd screenshot file and refreshes itsself (with javascript)if one has arrived ( checks every second )
    That way everytime I press F6 on my computer , screenhunter takes a screenshot and then the ftp happens and the remore refresh happens. No Flash . No Javascript. Just good clean fun.
    Trouble is , whilst I found a javascript timer, I can't seem to find a PHP one.
    Any ideas most welcome.
    Thanks.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    PHP doesn't have timers because few PHP scripts are intended to run longer than a couple seconds and most PHP scripts don't use multiple threads. However, you can do what you want to do using a while loop.
    PHP Code:
    set_time_limit(0);

    while(
    1) {
      
    // check screenshot
      
    sleep(1);

    You would not want to run this code in a web page though, because your browser will time out before the script does. You can run it via the command line on your local system.

    Your client-side script is going to have to use JavaScript unless you unconditionally refresh the image every second.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0
    Thanks , but I have to run it in a web page because that's how the sytem would work. Multiple students with the web page. That explains why the sleep function didn't work for me.

    Anyone got any other ideas for ways I might be able to do this ?

    Thanks.


    Originally Posted by E-Oreo
    PHP doesn't have timers because few PHP scripts are intended to run longer than a couple seconds and most PHP scripts don't use multiple threads. However, you can do what you want to do using a while loop.
    PHP Code:
    set_time_limit(0);

    while(
    1) {
      
    // check screenshot
      
    sleep(1);

    You would not want to run this code in a web page though, because your browser will time out before the script does. You can run it via the command line on your local system.

    Your client-side script is going to have to use JavaScript unless you unconditionally refresh the image every second.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0
    Actually, unconditionally refreshing the page every second doesn't sound quite so bad now. I think I'll try it. - Or maybe refershing a DIV content might be a litte more gentle if that can be done. I'll try it and see how it looks. I didn't want do that in case it caused flicker and because it didnt seem very efficient.


    Originally Posted by marcusHere
    Thanks , but I have to run it in a web page because that's how the sytem would work. Multiple students with the web page. That explains why the sleep function didn't work for me.

    Anyone got any other ideas for ways I might be able to do this ?

    Thanks.
  12. #7
  13. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    The part that you implement using a while loop would be on your end, for uploading the images.

    On the client-side, the part used by the students, you would use timers in JavaScript to periodically update the image.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0
    The php script run from a batch file to ftp the updated image works perfectly , but the constantly refreshing DIV doesnt work well becuase it flickers every time it reloads . I think this would irritate students.

    Originally Posted by marcusHere
    Actually, unconditionally refreshing the page every second doesn't sound quite so bad now. I think I'll try it. - Or maybe refershing a DIV content might be a litte more gentle if that can be done. I'll try it and see how it looks. I didn't want do that in case it caused flicker and because it didnt seem very efficient.

IMN logo majestic logo threadwatch logo seochat tools logo