|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Linha de comando
|
|
|
|
|
ipcs -> mostra blocos de memoria alocados
|
|
|
|
|
ipcrm -m "shmid" -> remove o bloco de mem<EFBFBD>ria referenciado por shmid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
ini_set('display_errors', 1);
|
|
|
|
|
*/
|
|
|
|
|
define("SHM_IPC_FILE_AGENTE", "/var/www/html/aplicativo/configs/ipcagente.txt");
|
|
|
|
|
define("SHM_SIZE_AGENTE", 1024);
|
|
|
|
|
define("SHM_SESSION_AGENTE", "SS_ShmIdAgente");
|
|
|
|
|
|
|
|
|
|
define("SHM_IPC_FILE_FILA", "/var/www/html/aplicativo/configs/ipcfila.txt");
|
|
|
|
|
define("SHM_SIZE_FILA", 1024);
|
|
|
|
|
define("SHM_SESSION_FILA", "SS_ShmIdFila");
|
|
|
|
|
define("SHM_ACESS_MODE", 'c');
|
|
|
|
|
define("SHM_ACESS_PERMISSION", 0644);
|
|
|
|
|
|
|
|
|
|
function ShmGetId($file) {
|
|
|
|
|
if (!file_exists($file)) {
|
|
|
|
|
touch($file);
|
|
|
|
|
}
|
|
|
|
|
return ftok($file, 'R');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmGetKey($file, $fsize) {
|
|
|
|
|
$shmkey = shmop_open(ShmGetId($file), SHM_ACESS_MODE, SHM_ACESS_PERMISSION, $fsize);
|
|
|
|
|
|
|
|
|
|
if (!$shmkey) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shmkey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmWrite($fdata, $shmkey) {
|
|
|
|
|
$fsize = strlen($fdata);
|
|
|
|
|
$shm_bytes_written = shmop_write($shmkey, $fdata, 0);
|
|
|
|
|
|
|
|
|
|
if ($shm_bytes_written != $fsize) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shm_bytes_written;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmRead($shmkey, $shm_size) {
|
|
|
|
|
$my_string = shmop_read($shmkey, 0, $shm_size);
|
|
|
|
|
if (!$my_string) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $my_string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmWriteVar($fdata, $shmkey) {
|
|
|
|
|
$fdata = serialize($fdata);
|
|
|
|
|
$fsize = strlen($fdata);
|
|
|
|
|
$shm_bytes_written = shmop_write($shmkey, $fdata, 0);
|
|
|
|
|
|
|
|
|
|
if ($shm_bytes_written != $fsize) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return $shm_bytes_written;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmReadVar($shmkey, $shm_size) {
|
|
|
|
|
$my_string = shmop_read($shmkey, 0, $shm_size);
|
|
|
|
|
if (!$my_string) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return unserialize($my_string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmDelete($shmkey) {
|
|
|
|
|
$size = @shmop_size($shmkey);
|
|
|
|
|
|
|
|
|
|
if (!@shmop_delete($shmkey)) {
|
|
|
|
|
ShmClose($shmkey);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
ShmClose($shmkey);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmClose($shmkey) {
|
|
|
|
|
return shmop_close($shmkey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShmIsKey($file) {
|
|
|
|
|
return shmop_open(ShmGetId($file), SHM_ACESS_MODE, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|