Voting

: seven minus seven?
(Example: nine)

The Note You're Voting On

hetii at poczta dot onet dot pl
17 years ago
Hi :)
I write small class for build bright message between my application.

<?
class Bright_Message
{

var $bright;
var $SHM_KEY;
var $my_pid;

function Bright_Message($SHM_KEY=null)
{
$this->my_pid = getmypid();//Get own pid
if (is_null($SHM_KEY)) $this->SHM_KEY = '123123123';
$this->bright = shm_attach($this->SHM_KEY, 1024, 0666);
$this->one_instance();
}

function get_msg($id,$remove=true)
{
if(@$msg=shm_get_var($this->bright,$id))
{
if ($remove) @shm_remove_var($this->bright,$id);
return $msg;
} else return false;
}

function snd_msg($id,$msg)
{
@shm_put_var($this->bright,$id,$msg);
return true;
}

function one_instance()
{
$SHM_PID = $this->get_msg(1,false);
if((strpos(exec('ps p'.$SHM_PID),$_SERVER['SCRIPT_FILENAME'])) === false)
$this->snd_msg(1,$this->my_pid); else
{
echo "This program exists on pid: $SHM_PID\r\n\r\n";
exit;
}
}

}
?>

send.php:
<?
include "bridge_message.class.php";
$shm = new Bright_Message();
$shm->snd_msg(2,'this is my simple message');
?>

receive.php:
<?
include "bridge_message.class.php";
$shm = new Bright_Message();
$msg = get_msg(2);
echo print_r($msg,1);
?>

<< Back to user notes page

To Top