Beispiel #1
0
 /** ProcessManager */
 public function buildWindowsProcessLockFile()
 {
     global $argv;
     $lockfile_name = str_replace(array('.', '\\', '/', ':'), '_', implode('_', $argv));
     $options = $this->container->get('config')->processmanager;
     $manager = Teamlab_Batch_ProcessManager_WindowsProcessLockfile::getInstance($options);
     $manager->setLockfileName($lockfile_name);
     return $manager;
 }
 public function lock()
 {
     if (!file_exists($this->_lockfile_dir)) {
         mkdir($this->_lockfile_dir, 0777, true);
     }
     if (file_exists($this->getLockfilePath())) {
         // return false; // ロックされている
         self::$_pid = file_get_contents($this->getLockfilePath());
         if (self::isRunning()) {
             return false;
         } else {
             // 前回ロックを作ったプロセスがロックを残したまま死亡した場合
             // ここでなにもしなければ無視して新規に今回実行時のプロセスIDでロックを上書き
         }
     }
     self::$_pid = getmypid();
     // 現在実行中の自分自身のPIDを取得する
     $ret = @file_put_contents($this->getLockfilePath(), self::$_pid);
     // PIDを書き込み
     if ($ret === false) {
         throw new Exception('ロックファイルが生成できませんでした');
     }
     return self::$_pid;
 }