...

View Full Version : Timed event in PHP?



rross46
06-19-2005, 11:38 AM
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?

raf
06-19-2005, 02:14 PM
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.

rross46
06-19-2005, 06:05 PM
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.

rollinlow54
06-19-2005, 06:26 PM
you could use meta refresh to refresh the page every 5 mins or so? or is that not what you're looking for

rross46
06-19-2005, 06:29 PM
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.

davehaz
06-19-2005, 06:37 PM
do you have access to change the time on the server? if so just change the system time and see what happens.

cyphix
06-19-2005, 06:54 PM
To test it why not just insert a temporary mail function so that it emails you when it runs & remove once done. ;)

raf
06-19-2005, 10:20 PM
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...

rross46
06-23-2005, 10:04 AM
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.

Extreme43
06-23-2005, 10:18 AM
$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()."'");

rross46
06-23-2005, 11:45 AM
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?

raf
06-24-2005, 10:13 PM
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/tutorials.cfm?id=155&type=PHP
googling will turn up hundreds of links on how to set up a cron.



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum