Miscellaneous
|
|
|
|
<? //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 the }//end function
// memory location and size of location to alloc function attachtomem($memloc, $alloc){
$sem_id=sem_get($memloc, 1);
sem_acquire($sem_id);
$shm = shm_attach($memloc, $alloc);
return $shm;
}// end function
$test = serialize("If you can read this, it is coming out of shared memory..");
$ms = ((strlen($test)+44)*2);
$sem_id = sem_get(memsegspot("test"), 1);
sem_acquire($sem_id);
$smh = shm_attach(memsegspot("test"), $ms);
echo "Attached to shm # $smhn";
shm_put_var($smh, $joi{md5($test)}, $test); // $shm_variable is the variable name, $test = the data
shm_put_var($smh, $another, serialize("some data"));
echo "placed data in shm.n";
$out = @shm_get_var($smh, ${md5($test)});
echo unserialize($out) . " n stored as: " . md5($out)."n";
@shm_detach($sem_id);
echo "detached from shared memory..n";
echo $ms . " bytes memory used.n"; ?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|