|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Linha de comando
|
|
|
|
|
ipcs -> mostra blocos de memoria alocados
|
|
|
|
|
ipcrm -m "shmid" -> remove o bloco de mem<EFBFBD>ria referenciado por shmid
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function ShmGetId($file) {
|
|
|
|
|
if (!file_exists($file)) {
|
|
|
|
|
touch($file);
|
|
|
|
|
}
|
|
|
|
|
return ftok($file, 'R');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmOpen($key, $flags = SHM_ACESS_MODE, $mode = SHM_ACESS_PERMISSION, $size = SHM_SIZE) {
|
|
|
|
|
$shmkey = shmop_open($key, $flags, $mode, $size);
|
|
|
|
|
|
|
|
|
|
if (!$shmkey) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shmkey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmWrite($shmkey, $data, $offset = 0) {
|
|
|
|
|
$fsize = strlen($data);
|
|
|
|
|
$shm_bytes_written = shmop_write($shmkey, $data, $offset);
|
|
|
|
|
|
|
|
|
|
if ($shm_bytes_written != $fsize) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shm_bytes_written;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmRead($shmkey, $start, $count) {
|
|
|
|
|
$my_string = shmop_read($shmkey, $start, $count);
|
|
|
|
|
if (!$my_string) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $my_string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmWriteVar($shmkey, $data, $offset) {
|
|
|
|
|
$fdata = serialize($fdata);
|
|
|
|
|
$fsize = strlen($fdata);
|
|
|
|
|
$shm_bytes_written = shmop_write($shmkey, $fdata, $offset);
|
|
|
|
|
|
|
|
|
|
if ($shm_bytes_written != $fsize) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shm_bytes_written;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmReadVar($shmkey, $start, $count) {
|
|
|
|
|
$my_string = shmop_read($shmkey, $start, $count);
|
|
|
|
|
if (!$my_string) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return unserialize($my_string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmDelete($shmkey) {
|
|
|
|
|
if (!@shmop_delete($shmkey)) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmClose($shmkey) {
|
|
|
|
|
return @shmop_close($shmkey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmExist($key) {
|
|
|
|
|
return @shmop_open($key, 'a', 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|