доброго времени суток
для обмена инфой между процессами написал класс шареной памяти на семафорах, но иногда апач падает с ошибкой в логах PHP Warning: sem_get(): failed acquiring SYSVSEM_SETVAL for key 0xb581327f: Numerical result out of range in sem_get
<?php
try{
class Sharedmem{
private $SharedMemSize=4194304;
private $SharedMemKey=134217728;
private $varKey=1;
private $Perm=0660;
private $prockey=null;
private $procname='prog1';
private $freesem=false;
private $maxuses=1;
private $autorelease=0;
private $sem_id=null;
public function __construct(){
$this->prockey=crc32($this->procname);
$this->sem_id=sem_get($this->prockey,$this->maxuses,$this->Perm,$this->autorelease);
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(!shm_has_var($shm_id,$this->varKey)){
$shm_val=[];
shm_put_var($shm_id,$this->varKey,$shm_val);
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}else{
throw new Exception('SHAREDMEM: Error create semaphore');
}
}
public function set($valname,$val){
$returnvalue=false;
if(!empty($valname)){
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(shm_has_var($shm_id,$this->varKey)){
$shm_val=shm_get_var($shm_id,$this->varKey);
if(sizeof($shm_val)+sizeof($val)<$this->SharedMemSize){
$shm_val[$valname]=$val;
if(shm_put_var($shm_id,$this->varKey,$shm_val)){
$returnvalue=true;
}
}
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
}else{
throw new exception('SHAREDMEM:get->Variable name is null');
}
return $returnvalue;
}
public function get($valname){
$returnvalue=false;
if(!empty($valname)){
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(shm_has_var($shm_id,$this->varKey)){
$shm_val=shm_get_var($shm_id,$this->varKey);
if(is_array($shm_val)){
if(isset($shm_val[$valname])){
$returnvalue=$shm_val[$valname];
}
}
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
return $returnvalue;
}else{
throw new exception('SHAREDMEM:get->Variable name is null');
}
}
public function unset($valname){
$returnvalue=false;
if(!empty($valname)){
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(shm_has_var($shm_id,$this->varKey)){
$shm_val=shm_get_var($shm_id,$this->varKey);
if(is_array($shm_val)){
unset($shm_val[$valname]);
if(shm_put_var($shm_id,$this->varKey,$shm_val)){
$returnvalue=true;
}
}
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
return $returnvalue;
}else{
throw new exception('SHAREDMEM:del->Variable name is null');
}
}
public function avail($valname){
$returnvalue=false;
if(!empty($valname)){
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(shm_has_var($shm_id,$this->varKey)){
$shm_val=shm_get_var($shm_id,$this->varKey);
if(isset($shm_val[$valname])){
$returnvalue=true;
}
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
return $returnvalue;
}else{
throw new exception('SHAREDMEM:avail->Variable name is null');
}
}
public function clear(){
$returnvalue=false;
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
shm_remove($shm_id);
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
return $returnvalue;
}
public function remove(){
$returnvalue=false;
if($this->sem_id){
sem_remove($this->sem_id);
$returnvalue=true;
}
return $returnvalue;
}
public function getlist(){
$returnvalue=false;
if($this->sem_id){
if(sem_acquire($this->sem_id,$this->freesem)){
$shm_id=shm_attach($this->SharedMemKey,$this->SharedMemSize,$this->Perm);
if($shm_id){
if(shm_has_var($shm_id,$this->varKey)){
$returnvalue=shm_get_var($shm_id,$this->varKey);
if(!is_array($returnvalue)){
$returnvalue=[];
}
}
shm_detach($shm_id);
}
sem_release($this->sem_id);
}
}
return $returnvalue;
}
}
}catch(exception $e){
}
?>
где я накосячил?