本文整理汇总了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");
}
}
}