Jump to content

Manual cron


Thomisback

Recommended Posts

Hello,

 

I am trying to make a manual cron system, I have created a MySQL table called "[cron]" with the fields "time" & "name". Field "name" is an index.

 

I am trying to run every hour in PHP, this is my code:

 

<?PHP

  if(isset($UPDATE_DB)) {
    $dbres                              = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `[cron]`");
    while($x = mysql_fetch_object($dbres))
      $update[$x->name]         = $x->time;

    if(floor($update['hour']/3600) != floor(time()/3600)) {
      $dbres                            = mysql_query("SELECT GET_LOCK('hour_update',0)");
      if(mysql_result($dbres,0) == 1) {
        $cron_pass                      = "secretcronpassword";
        mysql_query("UPDATE `[cron]` SET `time`=FROM_UNIXTIME(UNIX_TIMESTAMP(`time`)+'3600') WHERE `name`='hour'");
        -- Execute querys here
        mysql_query("SELECT RELEASE_LOCK('hour_update')");
      }
    }
?>

 

For some strange reason it updates every time I load it instead of every hour, does anyone know why this happens?

 

Thanks a lot!

Link to comment
https://forums.phpfreaks.com/topic/99974-manual-cron/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.