Welcome, Guest
  • Author Topic: how to execute a php script every few seconds  (Read 3597 times)

    david007

    • Seasoned Programmer
    • ***
    • Posts: 127
      • View Profile
    Hi all. i wonder how i can modify the following script so it executes a php script every 10 seconds(execute without refreshing the whole page every few seconds). I tried the following but it never execute the php script even once. i be happy if some one show me i can fix this problem.Thanks

    Code: [Select]
    <html>

    <head>
    <SCRIPT LANGUAGE = "JavaScript">
    <!--
    var secs
    var timerID = null
    var timerRunning = false
    var delay = 1000

    function InitializeTimer()
    {
        // Set the length of the timer, in seconds
        secs = 10
        StopTheClock()
        StartTheTimer()
    }

    function StopTheClock()
    {
        if(timerRunning)
            clearTimeout(timerID)
        timerRunning = false
    }

    function StartTheTimer()
    {
        if (secs==0)
        {
            StopTheClock()
            // Here's where you put something useful that's
            // supposed to happen after the allotted time.
            // For example, you could display a message:
            alert("You have just wasted 10 seconds of your life.")
            fetchData("./track.php");
        }
        else
        {
            self.status = secs
            secs = secs - 1
            timerRunning = true
            timerID = self.setTimeout("StartTheTimer()", delay)
        }
    }
    //-->
    </SCRIPT>


    </head>

    <body onLoad="InitializeTimer()" >

    </body>

    </html>
    « Last Edit: 03/20/07, 07:26 by david007 »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: how to execute a php script every few seconds
    « Reply #1 on: 03/20/07, 07:57 »
    how do you think a php script can be excuted without the page to be refreshed?
    PHP is a serverside scripting language, which outputs data or html pages.
    If you run it through normal calls (not remoting), the page has to be refreshed to show the new details.

    If you dont want to refresh the page, you better use either AJAX or FLASH as frontend.
    happy flashing
    8)
    Ronald

    david007

    • Seasoned Programmer
    • ***
    • Posts: 127
      • View Profile
    Re: how to execute a php script every few seconds
    « Reply #2 on: 03/20/07, 08:22 »
    how do you think a php script can be excuted without the page to be refreshed?
    PHP is a serverside scripting language, which outputs data or html pages.
    If you run it through normal calls (not remoting), the page has to be refreshed to show the new details.

    If you dont want to refresh the page, you better use either AJAX or FLASH as frontend.

    thank you for your reply. could you show me the ajax code that makes call to a php and executes it? My current php is just inserting users ip and time to mysql but i will expand it to do some more stuff. I be happy if u show me how to achive this frequent call to php.Thanks

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: how to execute a php script every few seconds
    « Reply #3 on: 03/20/07, 08:42 »
    Look into remoting with AJAX or Flash.
    I am not AJAX expert - all I know, AJAX works the same way as Flash-Remoting.
    I personaly prefer Flash Remoting
    happy flashing
    8)
    Ronald

    david007

    • Seasoned Programmer
    • ***
    • Posts: 127
      • View Profile
    Re: how to execute a php script every few seconds
    « Reply #4 on: 03/20/07, 08:46 »
    Look into remoting with AJAX or Flash.
    I am not AJAX expert - all I know, AJAX works the same way as Flash-Remoting.
    I personaly prefer Flash Remoting

    Thanks for giving me he search terms!! do you think flash remoting can have continouse conection with client for reciving info from client browser(ip,browser type..) and send data to user(sending popup page,updateing image,.. ?

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: how to execute a php script every few seconds
    « Reply #5 on: 03/20/07, 09:46 »
    If you want continous connection, you need a socketserver running.
    You can connect to a socket server with flash.
    But if you use AMFPHP, you have to query once in a while.
    If you setup an intelligent software only exchanging the most important data, you still can have a high responsive application without the backdrwas of a socketserver.

    Even with a socketserver, I would use the socket only for status information and exchange the larger packets vie http request.
    happy flashing
    8)
    Ronald