note 22132 added to function.shm-attach

From: Date: Fri, 07 Jun 2002 16:51:04 +0000
Subject: note 22132 added to function.shm-attach
Groups: php.notes 
Request: Send a blank email to php-notes+get-31570@lists.php.net to get a copy of this message
//shared memory example.. hope this helps // return a memory hex segment for string.. // limit four chars in Joel = 0x4a6f656c (joel is my name) function memsegspot($str){ $str = str_pad($str, 4, "Z"); // Z = 5a for ($a=0; $a<4; $a++){ $out1 = substr($str, $a , 1); // walk through $out .= dechex(ord($out1)); // ord returns dec, we need hex for shared memory segments }// return ("0x".$out); // prepend it with 0x }//end function $test = serialize("\nIf you can read this, it is coming out of shared memory..\n"); $ms = ((strlen($test)+44)*2); $sem_id = sem_get(memsegspot("test"), 1); echo $sem_id; sem_acquire($sem_id); $smh = shm_attach(memsegspot("test"), $ms); echo "Attached to shm # $smh\n"; shm_put_var ($smh, $shm_variable, $test); // $shm_variable is the variable stored, $test = the data echo "placed data in shm.\n"; echo shm_get_var($smh, $testing); @shm_detach($sem_id); echo "detached from shared memory.."; -- http://www.php.net/manual/en/function.shm-attach.php http://master.php.net/manage/user-notes.php?action=edit+22132 http://master.php.net/manage/user-notes.php?action=delete+22132 http://master.php.net/manage/user-notes.php?action=reject+22132

« previous php.notes (#31570) next »