本文整理汇总了PHP中sem_release函数的典型用法代码示例。如果您正苦于以下问题:PHP sem_release函数的具体用法?PHP sem_release怎么用?PHP sem_release使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_release函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: release
/**
* Release a semaphore
* After releasing the semaphore, acquire() may be called to re-acquire it.
*
* @return bool success
* @throws io.IOException
* @see xp://io.sys.Semaphore#acquire
*/
public function release()
{
if (FALSE === sem_release($this->_hdl)) {
throw new IOException('Could not release semaphore ' . $this->key);
}
return TRUE;
}
示例2: unlock
/**
* @return bool
*/
public function unlock()
{
$released = sem_release($this->lock);
sem_remove($this->lock);
$this->lock = null;
return $released;
}
示例3: registerChildPID
/**
* Registers the PID of a child-process
*
* @param int The PID
*/
public function registerChildPID($pid)
{
$sem_key = sem_get($this->crawler_uniqid);
sem_acquire($sem_key);
file_put_contents($this->working_directory . "pids", $pid . "\n", FILE_APPEND);
sem_release($sem_key);
}
示例4: getNextValueByShareMemory
/**
* 通过本机共享内存件来生成一个auto_increment序列
*
* 序列类似MySQL的auto_increment
*
* @access private
* @param void
* @return mixed
*/
function getNextValueByShareMemory()
{
$addr = '127.0.0.1';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$addr = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (!empty($_SERVER['SERVER_ADDR'])) {
$addr = $_SERVER['SERVER_ADDR'];
}
$skey = 'global_serial_generator_seed_' . $addr;
$ikey = crc32($skey);
$sem = $shm = null;
$retry_times = 1;
do {
$sem = sem_get($ikey, 1, 0777);
$shm = shm_attach($ikey, 128, 0777);
if (is_resource($sem) && is_resource($shm)) {
break;
}
$cmd = "ipcrm -M 0x00000000; ipcrm -S 0x00000000; ipcrm -M {$ikey} ; ipcrm -S {$ikey}";
$last_line = exec($cmd, $output, $retval);
} while ($retry_times-- > 0);
if (!sem_acquire($sem)) {
return false;
}
$next_value = false;
if (shm_has_var($shm, $ikey)) {
shm_put_var($shm, $ikey, $next_value = shm_get_var($shm, $ikey) + 1);
} else {
shm_put_var($shm, $ikey, $next_value = 1);
}
$shm && shm_detach($shm);
$sem && sem_release($sem);
return $next_value;
}
示例5: session_value
function session_value($name, $index)
{
global $shm_key, $shm_var, $sem_id;
switch ($index) {
case 'config':
$shm_size = 859;
break;
case 'ipdata':
$shm_size = 30050;
break;
default:
$shm_size = 0;
}
sem_acquire($sem_id['shlock']);
$shm_id = shmop_open($shm_key[$index], 'c', 0644, $shm_size);
if ($name == 'update') {
$shm_data = serialize($shm_var[$index]);
shmop_write($shm_id, str_pad($shm_data, $shm_size, "", STR_PAD_RIGHT), 0);
} else {
$shm_data = shmop_read($shm_id, 0, $shm_size);
$shm_var[$index] = @unserialize($shm_data);
}
shmop_close($shm_id);
sem_release($sem_id['shlock']);
}
示例6: generate
/**
* @return IdValue
*/
public function generate()
{
$timestamp = $this->generateTimestamp();
// Acquire semaphore
$semaphore = sem_get($this->semaphoreId);
sem_acquire($semaphore);
// Attach shared memory
$memory = shm_attach(self::SHM_KEY);
$sequence = 0;
if (!is_null($this->lastTimestamp) && $timestamp->equals($this->lastTimestamp)) {
// Get
$sequence = shm_get_var($memory, self::SHM_SEQUENCE) + 1 & $this->config->getSequenceMask();
// Increment sequence
shm_put_var($memory, self::SHM_SEQUENCE, $sequence);
if ($sequence === 0) {
usleep(1000);
$timestamp = $this->generateTimestamp();
}
} else {
// Reset sequence if timestamp is different from last one.
$sequence = 0;
shm_put_var($memory, self::SHM_SEQUENCE, $sequence);
}
// Detach shared memory
shm_detach($memory);
// Release semaphore
sem_release($semaphore);
// Update lastTimestamp
$this->lastTimestamp = $timestamp;
return new IdValue($timestamp, $this->regionId, $this->serverId, $sequence, $this->calculate($timestamp, $this->regionId, $this->serverId, $sequence));
}
示例7: release
/**
* Release a semaphore
* After releasing the semaphore, acquire() may be called to re-acquire it.
*
* @return bool success
* @throws io.IOException
* @see xp://io.sys.Semaphore#acquire
*/
public function release()
{
if (false === sem_release($this->_hdl)) {
throw new \io\IOException('Could not release semaphore ' . $this->key);
}
return true;
}
示例8: put
public static function put($killID, $raw)
{
$file = static::getFile($killID, true);
$sem = sem_get(5632);
// kmdb is 5632 on a phone
if (!sem_acquire($sem)) {
throw new Exception('Unable to obtain kmdb semaphore');
}
// Thread safe from here until sem_release
if (!file_exists($file)) {
$kills = array();
} else {
$contents = file_get_contents($file);
$deflated = gzdecode($contents);
$kills = unserialize($deflated);
$contents = null;
}
if (!isset($kills["{$killID}"])) {
$kills["{$killID}"] = $raw;
$contents = serialize($kills);
$compressed = gzencode($contents);
file_put_contents($file, $compressed, LOCK_EX);
}
sem_release($sem);
}
示例9: unlock
/**
* Unlock process
*
* @return Mage_Index_Model_Process
*/
public function unlock()
{
$this->_getSemIdentifier();
shm_remove_var($this->_shmId, $this->getIndexerCodeCrc());
@sem_release($this->_getSemIdentifier());
$this->_isLocked = false;
}
示例10: unlock
public function unlock()
{
if (PHP_OS !== 'Linux') {
return;
}
sem_release($this->getSemaphoreId());
$this->locked = false;
}
示例11: del
/**
* Delete shared memory var
*/
public function del()
{
sem_acquire($this->__mutex);
//block until released
@shm_remove_var($this->__shm, $this->__key);
sem_release($this->__mutex);
//release mutex
}
示例12: get
/**
* @param $key
* @param int $size
* @return mixed
*/
public function get($key, $size = 10000)
{
$result = $this->attach($key, $size);
sem_acquire($result['mutex']);
$value = @shm_get_var($result['shm'], $key);
sem_release($result['mutex']);
return $value;
}
示例13: release
/**
* release lock
* @throws \RuntimeException
*/
public function release()
{
if ($this->locked) {
if (!sem_release($this->lock_id)) {
throw new \RuntimeException('Cannot release semaphore: ' . $this->lock_id);
}
$this->locked = false;
}
}
示例14: __destruct
function __destruct()
{
if (null !== $this->shmHandle) {
shm_detach($this->shmHandle);
}
if (null !== $this->semHandle) {
sem_release($this->semHandle);
}
}
示例15: unlock
public static function unlock($sem_id)
{
if (substr(PHP_OS, 0, 3) == 'WIN') {
// if Windows OS detected just return true;
return true;
}
sem_release($sem_id);
// release semaphore lock
}