newb Posted July 15, 2009 Share Posted July 15, 2009 i want to create a php timer script to automatically set a variable after 48 hours after the timer has been started. how would i do this Link to comment https://forums.phpfreaks.com/topic/166014-php-timer-script/ Share on other sites More sharing options...
ignace Posted July 15, 2009 Share Posted July 15, 2009 A php script and a cron job (linux) or scheduled task (windows) Link to comment https://forums.phpfreaks.com/topic/166014-php-timer-script/#findComment-875655 Share on other sites More sharing options...
phporcaffeine Posted July 15, 2009 Share Posted July 15, 2009 <?php if (!file_exists('.cache')) { fwrite(fopen('.cache', 'w+'), time()); $origin = file_get_contents('.cache'); } else { $origin = file_get_contents('.cache'); } $distance = time() - $origin; if ($distance >= 172800) { //SET VARIABLE OR DO WHATEVER BECAUSE IT HAS BEEN 48 HOURS } ?> Place that in a folder that has write permissions and then fire it by Cron or Scheduled Task. Depending on what your having it do (and how intense it is), I would fire the job once a minute. Link to comment https://forums.phpfreaks.com/topic/166014-php-timer-script/#findComment-875687 Share on other sites More sharing options...
phporcaffeine Posted July 15, 2009 Share Posted July 15, 2009 if ($distance >= 172800) { //SET VARIABLE OR DO WHATEVER BECAUSE IT HAS BEEN 48 HOURS unlink('.cache'); } I forgot, but you'll want to add the 'unlink()' otherwise the timer wont count like it should after it hits 48 hours the first time Link to comment https://forums.phpfreaks.com/topic/166014-php-timer-script/#findComment-875709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.