How to replace cron with time()

This is a discussion on How to replace cron with time() within the PHP Language forums, part of the PHP Programming Forums category; I think this will do it: define('TIME24h', time() - 86400); $marker_array = file($marker_file); $marker_array_r = array_reverse($marker_array); if ($marker_array_r[0] < ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-05-2004
deko
 
Posts: n/a
Default How to replace cron with time()

I think this will do it:

define('TIME24h', time() - 86400);
$marker_array = file($marker_file);
$marker_array_r = array_reverse($marker_array);
if ($marker_array_r[0] < TIME24h)
{
$rolltime = $marker_array_r[0] + 86400;
while ($rolltime < TIME24h) //if no visits in last 24hrs
{
$rolltime = $rolltime + 86400;
}
$fp = fopen($marker_file,"a");
fwrite($fp, $rolltime);
fclose($fp);
//code that needs to run once a day goes here
}

The next visit to the site after a 24-hour interval will trigger the code.
The marker_file will also serve as a log showing each day the scheduled code
was run. Of course this assumes you seed the marker_file with a unix
timestamp of your choice, and that you only need your code to run once each
day, not at a particular time each day.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0