All pastes #56952 Raw Edit

Mine

public php v1 · immutable
#56952 ·published 2006-05-18 21:24 UTC
rendered paste body
#!/usr/bin/php<?phpdefine('TIMEOUT', 1000);define('VARKEY', 1337);define('SEMKEY', 1);define('MSGKEY', 2);define('MSG_UP', 1);define('MSG_DOWN', 2);define('MSG_MAXSIZE',sizeof('1')*20);$shm_key 	= ftok(dirname(__FILE__),'a'); 		//get our shm_key$sem_id		= sem_get(SEMKEY);			//get our semaphore ID$shm_id		= shm_attach($sem_id, TIMEOUT);		//get the id for the SHM block$msg_queue      = msg_get_queue( MSGKEY,0600);          //get our message queue$msg_type	= 0;$msg_value	= null;echo "nice nap.  starting loop\n";while ($msg_type != MSG_DOWN){	if( msg_receive($msg_queue, 0, $msg_type, MSG_MAXSIZE, $msg_value, false))	{		if( $msg_type == MSG_UP )		{			if (sem_acquire($sem_id))			{				echo shm_get_var($shm_id,VARKEY)."\n";				sem_release($sem_id);			}			else			{				echo "Could not aquire semaphore!\n";			}		}	}	else	{		Echo "error!";	}}echo "detaching from shm and sleeping 10 seconds";shm_detach($shm_id);?>