PABX da Simples IP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.1 KiB

<?php
/*
Linha de comando
ipcs -> mostra blocos de memoria alocados
ipcrm -m "shmid" -> remove o bloco de mem<EFBFBD>ria referenciado por shmid
*/
define("SHM_SIZE", 2048);
define("SHM_ACESS_MODE_C", 'c');
define("SHM_ACESS_MODE_R", 'a');
define("SHM_ACESS_MODE_RW", 'w');
define("SHM_ACESS_PERMISSION", 0666);
function ShmGetId($file) {
/**
* Se for passado um id, retorna se n<EFBFBD>o obtem a partir de um arquivo.
*/
if (is_numeric($file)) {
return $file;
}
if (!file_exists($file)) {
touch($file);
}
return ftok($file, 'R');
}
function ShmOpen($key, $flags, $perms, $size) {
$shmkey = shmop_open($key, $flags, $perms, $size);
if (!$shmkey) {
return false;
}
return $shmkey;
}
function ShmClear($shmkey, $offset, $length) {
$shm_bytes_written = shmop_write($shmkey, str_repeat(' ', $length), $offset);
if ($shm_bytes_written != $length) {
return false;
}
return $shm_bytes_written;
}
function ShmWrite($shmkey, $data, $offset = 0) {
$fsize = strlen($data);
$shm_bytes_written = shmop_write($shmkey, $data, $offset);
if ($shm_bytes_written != $fsize) {
return false;
}
return $shm_bytes_written;
}
function ShmRead($shmkey, $start, $count) {
$my_string = shmop_read($shmkey, $start, $count);
if (!$my_string) {
return false;
}
return $my_string;
}
function ShmWriteVar($shmkey, $data, $offset) {
$fdata = serialize($data);
$fsize = strlen($fdata);
$shm_bytes_written = shmop_write($shmkey, $fdata, $offset);
if ($shm_bytes_written != $fsize) {
return false;
}
return $shm_bytes_written;
}
function ShmReadVar($shmkey, $start, $count) {
$my_string = shmop_read($shmkey, $start, $count);
if (!$my_string) {
return false;
}
return unserialize($my_string);
}
function ShmDelete($shmkey) {
if (!@shmop_delete($shmkey)) {
return false;
}
return true;
}
function ShmClose($shmkey) {
return shmop_close($shmkey);
}
function ShmExist($key) {
return shmop_open($key, 'a', 0, 0);
}
function ShmSize($shmkey) {
return shmop_size($shmkey);
}
?>