note 114894 added to function.shm-attach
| From: | novayear#hotmail | Date: | Mon, 21 Apr 2014 20:13:48 +0000 |
| Subject: | note 114894 added to function.shm-attach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199313@lists.php.net to get a copy of this message | ||
small shm class..
example usage:
$shx= new shmSmart;
$shx->put("key_name_apple","key_val_peach"); //set example..
$shx->put("key name alternative
array",array(1=>"banana","apricot","blablabla"=>array("new-blaala")));
//set array example..
echo $shx->get("key_name_apple"); // get example key value.
$shx->del("key_name_apple"); // delete key
unset($shx); // free memory in php..
class shmSmart{
public $shm; //holds shared memory resource
public function __construct(){
if(function_exists("shm_attach")===FALSE){
die("\nYour PHP configuration needs adjustment. See: http://us2.php.net/manual/en/shmop.setup.php.
To enable the System V shared memory support compile PHP with the option --enable-sysvshm.");
}
$this->attach(); //create resources (shared memory)
}
public function attach(){
$this->shm=shm_attach(0x701da13b,33554432); //allocate shared memory
}
public function dettach(){
return shm_detach($this->shm); //allocate shared memory
}
public function remove(){
return shm_remove($this->shm); //dallocate shared memory
}
public function put($key,$var) {
return shm_put_var($this->shm,$this->shm_key($key),$var); //store var
}
public function get($key){
if($this->has($key)){
return shm_get_var($this->shm,$this->shm_key($key)); //get var
}else{
return false;
}
}
public function del($key){
if($this->has($key)){
return shm_remove_var($this->shm,$this->shm_key($key)); // delete var
}else{
return false;
}
}
public function has($key){
if(shm_has_var($this->shm,$this->shm_key($key))){ // check is isset
return true;
}else{
return false;
}
}
public function shm_key($val){ // enable all world langs and chars !
return
preg_replace("/[^0-9]/","",(preg_replace("/[^0-9]/","",md5($val))/35676248)/619876);
// text to number system.
}
public function __wakeup() {
$this->attach();
}
public function __destruct() {
$this->dettach();
unset($this);
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 46.1.185.65
----
Manual Page -- http://php.net/manual/en/function.shm-attach.php
Edit -- https://master.php.net/note/edit/114894
Del: integrated -- https://master.php.net/note/delete/114894/integrated
Del: useless -- https://master.php.net/note/delete/114894/useless
Del: bad code -- https://master.php.net/note/delete/114894/bad+code
Del: spam -- https://master.php.net/note/delete/114894/spam
Del: non-english -- https://master.php.net/note/delete/114894/non-english
Del: in docs -- https://master.php.net/note/delete/114894/in+docs
Del: other reasons-- https://master.php.net/note/delete/114894
Reject -- https://master.php.net/note/reject/114894
Search -- https://master.php.net/manage/user-notes.php