I found a good way to do that:
<?php
function application_start (){
global $_APP;
global $shm_id;
$shm_id = shmop_open(0xff3, “c”, 0644, 10000);
$shm_size = shmop_size($shm_id);
$data = shmop_read($shm_id, 0, $shm_size);
$
}
function application_end ()
{
global $_APP;
global $shm_id;
$data = serialize($
shmop_write($shm_id, $data, 0);
shmop_close($shm_id);
}
?>
Then in the program:
<?php
application_start();
..
.. use $_APP to store the application scope variables
..
application_end();
?>
?
for a larger room to store the variables: (but slower)
<?php
define(“APP_DATA_FILE”,
“/tmp/application.data”);
function application_start (){
global $_APP;
// if data file exists, load application
// variables
if (file_exists(APP_DATA_FILE)){
// read data file
$file = fopen(APP_DATA_FILE, “r”);
if ($file){
$data = fread($file,
filesize(APP_DATA_FILE));
fclose($file);
}
// build application variables from
// data file
$
}
}
function application_end (){
global $_APP;
// write application data to file
$data = serialize($
$file = fopen(APP_DATA_FILE, “w”);
if ($file){
fwrite($file, $data);
fclose($file);
}
}
?>
Here is an example using Application variables to communicate with different users.
A drawing board online:
[url]http://pighouse.webonlive.com/jason/drawingboard/
source:
[url]http://pighouse.webonlive.com/jason/drawingboard.zip
u can use different username or ip, and every user online at the same time can see other users’ drawing.