Example #1
0
 public function actionProcessSMS()
 {
     define('LOCK_SUFFIX', '.locksms');
     if (($pid = cronHelper::lock()) !== FALSE) {
         echo 'cron running sms';
         $this->ProcessSMS();
         sleep(1);
         // Cron job code for demonstration
         cronHelper::unlock();
     } else {
         echo "CRON LOCK";
     }
 }
Example #2
0
 public static function lock()
 {
     global $argv;
     $lock_file = LOCK_DIR . basename($argv[0] . LOCK_SUFFIX);
     if (file_exists($lock_file)) {
         self::$pid = file_get_contents($lock_file);
         if (self::isrunning()) {
             error_log("==" . self::$pid . "== Already in progress...");
             return FALSE;
         } else {
             error_log("==" . self::$pid . "== Previous job died abruptly...");
         }
     }
     self::$pid = getmypid();
     file_put_contents($lock_file, self::$pid);
     error_log("==" . self::$pid . "== Lock acquired, processing the job...");
     return self::$pid;
 }