Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Timed event in PHP?

    Hey guys i was wondering how to go about setting up a timed event, that say every 5 minutes, items in a table will get updated. i have no idea of how to go about this, anyone got any ideas?

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP alone can't do this. (Well not in an efficient way).
    You need to write a PHP script that does your db-manipulation, and then request this page every 5 minutes with a CRON (Unix) or a scheduled task (Windows).

    if you run a search here or on google for "CRON" or "scheduled taks" then you'll find all the info you need.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    right dude ive managed to create the cron job, i not sure if it is right though.
    i created it in cpanel. how do i display like a timer till cron job in php?? so i can test it works.

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could use meta refresh to refresh the page every 5 mins or so? or is that not what you're looking for

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    dont think so, i need data to be updated every 5 minutes. ive created a cron job but got no idea how to test it.

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do you have access to change the time on the server? if so just change the system time and see what happens.

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    To test it why not just insert a temporary mail function so that it emails you when it runs & remove once done.

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just add a column of type TIMESTAMP in the table that you update.
    Every time the record is updated, this timestampvalue will also be updated (unless you already have a timestamp-column inthere)
    Or else just insert a record into some db-table with a timestamp-column...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so how would a command like that look in the cron job menu??? that is what sort of throws me. what do i type as a command so tha things will be updated.

  • #10
    New Coder
    Join Date
    Mar 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $timestamp mysql_query("SELECT timestamp FROM table");
    $msll = ((time() - $timestamp) / 300); 
    $msll round($msll);

    while(
    $msll >= '1')
    {
    //do ya stuff
    // it wil do it for every 5 minutes that has passed since last time the page was viewed
    }
    mysql_query("UPDATE table SET timestamp='".time()."'"); 

  • #11
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    do i save that php code then just call it in the command??

    edit, i not sure what a timestamped field attributes should look like, or even what it means, can someone enlighten me?
    Last edited by rross46; 06-23-2005 at 01:08 PM.

  • #12
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rross46
    do i save that php code then just call it in the command??
    No. The CRON will resuest a PHP-file. And inside that file, you add the PHP code for your tableupdate or whatever. Just like in a regular PHP-page.
    Only now, the CRON will request the page, usually through Lynx or some other small browser
    here's a short tutorial: http://www.htmlcenter.com/tutorials/...d=155&type=PHP
    googling will turn up hundreds of links on how to set up a cron.

    Quote Originally Posted by rross46
    edit, i not sure what a timestamped field attributes should look like, or even what it means, can someone enlighten me?
    code to add a new column of type TIMESTAMP to a table

    ALTER TABLE `yourtablename` ADD `yourcolumnname` TIMESTAMP

    you should replace "yourtablename" by the tablename you wanna add the timestampcolumn to + you should replace "yourcolumnname" by the columnnamename you prefer.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •