Cron job in php

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
FishBird
New php-forum User
New php-forum User
Posts: 21
Joined: Thu Apr 12, 2012 8:05 am
Contact:

Thu Apr 12, 2012 10:53 am

You needto set a cronjob on the server itself. You cannot start a script just by itself.

To get it working without using real cronjobs, you can store in your databse when your cron last runned, and let a user activate it:

Code: Select all

$last_runned = $db->query("SELECT `last_run` FROM `lastrunned` LIMIT 1");
$last_runned = $db->fetch(2);
if( $last_runned['last_run'] + 300 < time() ){
 do_crontab_script();
 $db->query("UPDATE `lastrunned` SET `last_run` = ?", array( $time()) );
} 
Something like that.

Post Reply