PHP Classes
Icontem

File: sharedmemory.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Keizer  >  Shared Memory  >  sharedmemory.class.php  
File: sharedmemory.class.php
Role: Class source
Content type: text/plain
Description: Mainclass
Class: Shared Memory
Store and retrieve information in shared memory
 

Contents

Class file image Download
<?

    
// 
    // SharedMemory class 
    // 
    // Freeware 
    // you can use this freely without any warranty 
    // comments are appreciated: r.keizer qwerty vestingfinance.nl (replace qwerty with @) 


    
class SharedMemory {
        
public $key;                //unique identifier for the shared memory block
        
public $shm;                //holds shared memory resource
        
public $mutex;            //holds the mutex
        
public $size;                //bytes to allocate
        
        
public function __construct($key=3354354334$size=10000) {        //default key, can be overridden, same for size
            
$this->key $key;
            
$this->size $size;
            
$this->Attach();    //create resources (shared memory + mutex)
        
}
        

        
        
//create resources
        
public function Attach() {
            
$this->shm shm_attach($this->key$this->size);    //allocate shared memory
            
$this->mutex sem_get($this->key1);        //create mutex with same key
        
}
        
        
//write to shared memory
        
public function Set($var) {
            
sem_acquire($this->mutex);    //block until released
            
shm_put_var($this->shm$this->key$var);    //store var 
            
sem_release($this->mutex);    //release mutex    
        
}
        
        
//read from shared memory
        
public function Get() {
            
sem_acquire($this->mutex);    //block until released
            
$var = @shm_get_var($this->shm$this->key);    //read var        
            
sem_release($this->mutex);    //release mutex
            
return $var;        
        }

        
// in case you want to serialize/unserialize the sharedmemory object 
        // this method restores all resources after unserializing
        
public function __wakeup() {
            
$this->Attach();
        }

    }





?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products