本文整理汇总了PHP中shm_attach函数的典型用法代码示例。如果您正苦于以下问题:PHP shm_attach函数的具体用法?PHP shm_attach怎么用?PHP shm_attach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shm_attach函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Map2GE
function Map2GE($x, $y)
{
if (0) {
$SHM_KEY = ftok(__FILE__, chr(4));
$data = shm_attach($SHM_KEY, 102400, 0666);
$result = shm_get_var($data, 1);
$r = $result[$x][$y];
if (isset($r)) {
shm_detach($data);
return $r;
}
}
// ×¥¿
$r = t67to97($x, $y);
$x = $r[0];
$y = $r[1];
$proj = "proj -I +proj=tmerc +ellps=aust_SA +lon_0=121 +x_0=250000 +k=0.9999";
$ret = shell_exec("echo {$x} {$y} | {$proj}");
if (preg_match("/(\\d+)d(\\d+)'([\\d.]+)\"E\\s+(\\d+)d(\\d+)'([\\d.]+)\"N/", $ret, $matches)) {
list($junk, $ed, $em, $es, $nd, $nm, $ns) = $matches;
$r[0] = $ed + $em / 60 + $es / 3600;
$r[1] = $nd + $nm / 60 + $ns / 3600;
if (0) {
$result[$x][$y] = $r;
shm_put_var($data, 1, $result);
shm_detach($data);
}
return $r;
}
return FALSE;
// exit;
}
示例2: alloc
/**
* Memory alloc
*/
protected function alloc()
{
if (null !== $this->memory) {
return;
}
$this->memory = shm_attach(ftok(__FILE__, $this->identifier), $this->segmentSize, 0644);
}
示例3: __construct
public function __construct(string $namespace = null)
{
if (is_null($namespace)) {
$namespace = isset($_SERVER['PWD']) ? $_SERVER['PWD'] : 'SHM';
}
$this->_shmid = shm_attach(crc32($namespace));
}
示例4: flush
/**
* Flush entire cache.
*/
function flush()
{
parent::flush();
// remove and reconnect to the SHM block
shm_remove($this->shmid);
$this->shmid = shm_attach($this->shmkey, $this->memsize, 0600);
}
示例5: __construct
/**
* @param int $id
* @param Lock $lock
*/
public function __construct($id, LockInterface $lock)
{
$this->id = $id;
$this->lock = $lock;
$this->memory = shm_attach($this->id);
$this->updateNbProcess(+1);
}
示例6: __construct
public function __construct()
{
if (!function_exists('shm_attach')) {
throw new \RuntimeException('You need to enabled Shared Memory System V(see more "Semaphore")');
}
$this->shared_memory_segment = shm_attach(time() + rand(1, 1000));
}
示例7: __wakeup
/**
* Wake up from a sleep
*/
function __wakeup()
{
$this->id = sem_get($this->key);
shm_attach($this->id);
$this->refreshMemoryVarList();
shm_put_var($this->id, 1, shm_get_var($this->id, 1) + 1);
}
示例8: 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;
}
示例9: 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));
}
示例10: open
public function open()
{
$this->shm = shm_attach($this->ipckey, 256000, 0666);
if (!$this->shm) {
throw new \Exception("Could not open shared memory segment");
}
}
示例11: __construct
private function __construct()
{
$this->id = @shm_attach(55, 10000, 0600);
if (!$this->id) {
throw new \Exception('Нет доступа к общей памяти');
}
}
示例12: attach
/**
* Create shared memory block
*/
private function attach()
{
$this->__key = ftok($this->__path, $this->__proj_id);
$this->__shm = shm_attach($this->__key, $this->__size);
//allocate shared memory
$this->__mutex = sem_get($this->__key, 1);
//create mutex with same key
}
示例13: initializeShm
protected function initializeShm()
{
if (null !== $this->shmHandle) {
return;
}
$this->shmHandle = shm_attach($this->getId(), 60 * 1024);
$this->semHandle = sem_get($this->getId());
}
示例14: open
public function open()
{
$perms = $this->config['shared_memory.permissions'];
$size = $this->config['rabbitmq.max_workers'] * 44;
$file = $this->tmp_file;
$this->shm_res = shm_attach(ftok($file, 'L'), $size, $perms);
$this->logger->debug('Opening shared memory resource with id: [' . intval($this->shm_res) . '] on file [' . $this->tmp_file . ']');
}
示例15: pleac_Sharing_Variables_in_Different_Processes
function pleac_Sharing_Variables_in_Different_Processes()
{
// sharetest - test shared variables across forks
$SHM_KEY = ftok(__FILE__, chr(1));
$handle = sem_get($SHM_KEY);
$buffer = shm_attach($handle, 1024);
// The original recipe has an INT signal handler here. However, it
// causes erratic behavior with PHP, and PHP seems to do the right
// thing without it.
for ($i = 0; $i < 10; $i++) {
$child = pcntl_fork();
if ($child == -1) {
die('cannot fork');
} elseif ($child) {
$kids[] = $child;
// in case we care about their pids
} else {
squabble();
exit;
}
}
while (true) {
print 'Buffer is ' . shm_get_var($buffer, 1) . "\n";
sleep(1);
}
die('Not reached');
function squabble()
{
global $handle;
global $buffer;
$i = 0;
$pid = getmypid();
while (true) {
if (preg_match("/^{$pid}\\b/", shm_get_var($buffer, 1))) {
continue;
}
sem_acquire($handle);
$i++;
shm_put_var($buffer, 1, "{$pid} {$i}");
sem_release($handle);
}
}
// Buffer is 14357 1
// Buffer is 14355 3
// Buffer is 14355 4
// Buffer is 14354 5
// Buffer is 14353 6
// Buffer is 14351 8
// Buffer is 14351 9
// Buffer is 14350 10
// Buffer is 14348 11
// Buffer is 14348 12
// Buffer is 14357 10
// Buffer is 14357 11
// Buffer is 14355 13
// ...
}