Guest User

Tasks cron

a guest
Jun 8th, 2010
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. if (!class_exists('tasks')) include '/home/way_to_module/tasks.inc';
  3.  
  4. $lock_file='/home/user/tmpdir/lockfile.name';
  5.  
  6. if (file_exists($lock_file))
  7. {
  8.     if (filemtime($lock_file)>(time()-10800)) exit;
  9. }
  10. $lock_fh=fopen($lock_file,'w');
  11.  
  12. $starttime=time();
  13. $tasks=tasks::get_tasks();
  14. if (!empty($tasks))
  15. {
  16.     $q=array();
  17.     foreach ($tasks as $task) $q[$task->priority][]=$task;
  18.     ksort($q);
  19.     foreach ($q as $priority)
  20.     {
  21.         foreach ($priority as $task)
  22.         {
  23.             tasks::execute($task);
  24.             if ((time()-$starttime)>100) break;
  25.         }
  26.         if ((time()-$starttime)>100) break;
  27.     }
  28. }
  29. fclose($lock_fh);
  30. unlink($lock_file);
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment