本文整理汇总了PHP中shm_attach函数的典型用法代码示例。如果您正苦于以下问题:PHP shm_attach函数的具体用法?PHP shm_attach怎么用?PHP shm_attach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shm_attach函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:KevinStoneCode,项目名称:twmap,代码行数:32,代码来源:kml_lib.php
示例2: alloc
/**
* Memory alloc
*/
protected function alloc()
{
if (null !== $this->memory) {
return;
}
$this->memory = shm_attach(ftok(__FILE__, $this->identifier), $this->segmentSize, 0644);
}
开发者ID:cityware,项目名称:city-shared-memory,代码行数:10,代码来源:Bloc.php
示例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));
}
开发者ID:boyxp,项目名称:bluefin-base,代码行数:7,代码来源:shm.php
示例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);
}
开发者ID:jvinet,项目名称:pronto,代码行数:10,代码来源:shm.php
示例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);
}
开发者ID:CrakLabs,项目名称:ipc-component,代码行数:11,代码来源:ShmMemory.php
示例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));
}
开发者ID:vatson,项目名称:isolated-callback,代码行数:7,代码来源:SharedMemory.php
示例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);
}
开发者ID:hiveclick,项目名称:mojavi,代码行数:10,代码来源:SharedMemory.php
示例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;
}
开发者ID:fixbugs,项目名称:pubfunc-php,代码行数:43,代码来源:pub.serial.php
示例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));
}
开发者ID:ada-u,项目名称:chocoflake,代码行数:34,代码来源:IdWorkerOnSharedMemory.php
示例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");
}
}
开发者ID:noccy80,项目名称:cherryphp,代码行数:7,代码来源:ipcsharedobject.php
示例11: __construct
private function __construct()
{
$this->id = @shm_attach(55, 10000, 0600);
if (!$this->id) {
throw new \Exception('Нет доступа к общей памяти');
}
}
开发者ID:pers1307,项目名称:levelUpPHP,代码行数:7,代码来源:MemApplicationRegistry.php
示例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
}
开发者ID:nejtr0n,项目名称:shmestage,代码行数:11,代码来源:SharedMemory.php
示例13: initializeShm
protected function initializeShm()
{
if (null !== $this->shmHandle) {
return;
}
$this->shmHandle = shm_attach($this->getId(), 60 * 1024);
$this->semHandle = sem_get($this->getId());
}
开发者ID:emente,项目名称:kataii---kata-framework-2.x,代码行数:8,代码来源:event.php
示例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 . ']');
}
开发者ID:brutalsys,项目名称:rmq_worker,代码行数:8,代码来源:SHM.php
示例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
// ...
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:57,代码来源:Sharing_Variables_in_Different_Processes.php
示例16: connect
protected function connect($vbb90bf734107ea3b2f4c14a5d4bc4f91)
{
$this->segmentKey = shm_attach($vbb90bf734107ea3b2f4c14a5d4bc4f91, self::segmentSize, self::segmentPermissions);
if ($v6a992d5529f459a44fee58c733255e86 = @shm_get_var($this->segmentKey, 1)) {
$this->index = $v6a992d5529f459a44fee58c733255e86;
} else {
shm_put_var($this->segmentKey, 1, array(0 => false));
}
}
开发者ID:BGCX261,项目名称:zimmerli-svn-to-git,代码行数:9,代码来源:shm.php
示例17: __construct
/**
* @brief
*
* @param
* @return
*/
function __construct($filename)
{
if (!file_exists($filename)) {
touch($filename);
chmod($filename, 0666);
}
$this->ipckey = ftok($filename, 'i');
$this->shmres = shm_attach($this->ipckey, 1 << 16);
}
开发者ID:noccy80,项目名称:lepton-ng,代码行数:15,代码来源:ipc.php
示例18: __construct
public function __construct($channel)
{
$this->ipcFile = sys_get_temp_dir() . "/{$channel}.ipc";
@touch($this->ipcFile);
$this->ipc = ftok($this->ipcFile, 's');
// s for shm
$this->ipc = shm_attach($this->ipc);
// leave $memsize to php.ini
}
开发者ID:Victopia,项目名称:prefw,代码行数:9,代码来源:SharedMemory.php
示例19: attach
/**
* connect shared memory
*
* @param string $file
*/
public function attach($file = __FILE__)
{
//增加客户端连接数
$file = basename($file);
$tmp_file = '/tmp/' . substr($file, 0, strrpos($file, '.')) . 'lock';
touch($tmp_file);
$key = ftok($tmp_file, 'a');
$this->shm = shm_attach($key, $this->size);
//allocate shared memory
}
开发者ID:jzxyouok,项目名称:simple-fork-php,代码行数:15,代码来源:SharedMemory.php
示例20: __construct
/**
* Constructor shmDriver
*
* @param Translator $translator Translator service
* @param array $options Options driver
*/
public function __construct($translator, array $options = array())
{
parent::__construct($translator, $options);
$key = ftok(__FILE__, 'm');
$this->shmId = shm_attach($key, 100, 0666);
if (!$this->shmId) {
throw new \RuntimeException('Can\'t allocate shared memory');
}
$this->options = $options;
}
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:16,代码来源:ShmDriver.php
注:本文中的shm_attach函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论