{
//attach to shared memory
//make the memory 1K in size
$mem = shm_attach(SHM_COREPHP, 1024);
//attempt to get message variable, which
//won't be there the first time
if($old_message = shm_get_var($mem,
SHMVAR_MESSAGE);
{
print("Previous value: $old_message
\n");
}
//create new message
$new_message = getmypid(). " here at ".
microtime();
//set new value
shm_put_var($mem, SHMVAR_MESSAGE,
$new_message);
//detach from shared memory
shm_detach($mem);
//release semaphore
sem_release($sem);
}
else
{
//we failed to acquire the semaphore
print("Failed to acquire semaphore!
\n");
}
?>
boolean shm_detach(integer identifier)
Use shm_detach to free the memory associated with the identifier for a shared
memory segment. This does not release the shared memory itself. Use shm_remove to
do this.
value shm_get_var(integer identifier, integer key)
The shm_get_var function returns a value stored in a variable with shm_put_var.
boolean shm_put_var(integer identifier, integer key, value)