本文整理匯總了PHP中Lock::_PID方法的典型用法代碼示例。如果您正苦於以下問題:PHP Lock::_PID方法的具體用法?PHP Lock::_PID怎麽用?PHP Lock::_PID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Lock
的用法示例。
在下文中一共展示了Lock::_PID方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: lock
public static function lock($log)
{
$lock_file = BASE_PATH . '/.lock';
// check if lock file exists
if (file_exists($lock_file)) {
// get pid of locking process
self::$_PID = file_get_contents($lock_file);
// check if we locked it by ourselfs
if (self::$_PID == getmypid()) {
return TRUE;
}
// check if process is still running
if (self::running()) {
$log->log(\Psr\Log\LogLevel::INFO, "AIESEC-Customer.io-Connector is still running with pid " . self::$_PID);
return FALSE;
} else {
$log->log(\Psr\Log\LogLevel::ERROR, "AIESEC-Customer.io-Connector died. Please look into this accident and then manually delete the .lock-file");
die;
}
} else {
// get our own pid
self::$_PID = getmypid();
// try to get the lock
if (file_put_contents($lock_file, self::$_PID) > 0) {
// sleep 1s
sleep(1);
// check that we really got the lock
if (self::$_PID == file_get_contents($lock_file)) {
$log->log(\Psr\Log\LogLevel::INFO, "Process " . self::$_PID . " locked the base directory");
return self::$_PID;
} else {
$log->log(Psr\Log\LogLevel::WARNING, "Some process overwrote the lock for process " . self::$_PID);
return FALSE;
}
} else {
$log->log(\Psr\Log\LogLevel::ERROR, "Couldn't write lock-file. Please make the base directory writeable for the php process");
}
}
}