options['pidDate'] = $date; $this->remove = true; $this->fileName = strstr(basename((debug_backtrace()[0]["file"])), '.', true); $this->PidCheck(); } private function PidFile() { return sprintf('/tmp/%s%s.pid', $this->fileName, ($this->options['pidDate'] ? ("-" . date('Ymd')): '')); } private function PidCheck() { $this->PidRemoveAuto(); if (file_exists($this->PidFile())) { $this->remove = false; exit(0); } $this->PidCreate(); return true; } private function PidCreate() { file_put_contents($this->PidFile(), getmypid() . "|" . time()); } public function PidRemove() { if ($this->remove && file_exists($this->PidFile())) { unlink($this->PidFile()); } } private function PidRemoveAuto(){ if(!file_exists($this->PidFile())){ return false; } $strFile = file_get_contents($this->PidFile()); $timeexec = explode("|", $strFile); if($timeexec[1] <= strtotime('-2 hour')){ unlink($this->PidFile()); } } /** * Connect clone. */ private function __clone() { } }