PHP
downloads | documentation | faq | getting help | mailing lists | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

msg_queue_exists> <ftok
Last updated: Fri, 14 Nov 2008

view this page in

msg_get_queue

(PHP 4 >= 4.3.0, PHP 5)

msg_get_queue Message Queue anlegen oder an existierende Queue anbinden

Beschreibung

resource msg_get_queue ( int $key [, int $perms ] )

msg_get_queue() gibt eine ID zurück die für den Zugriff auf die mit dem gegbenen key bezeichnete System V Message Queue genutzt werden kann. Existiert die Message Queue noch nicht so wird sie mit den im optionalen Parameter perms angegebenen Rechten angelegt. Ein weiterer Aufruf von msg_get_queue() mit dem gleichen key liefert eine andere ID, beide IDs greifen aber intern auf die gleiche Message Queue zu.

Parameter-Liste

key

Numerische ID der Message Queue.

perms

Zugriffsrechte der Queue. Vorgabewert ist 0666. Existiert die Message Queue bereits so wird dieser Parameter ignoriert.

Rückgabewerte

Liefert ein Resourcehandle für den Zugriff auf eine System V Message Queue.



msg_queue_exists> <ftok
Last updated: Fri, 14 Nov 2008
 
add a note add a note User Contributed Notes
msg_get_queue
martin dot velek at gmail dot com
01-Aug-2007 04:23
Lack of IPC_EXCL makes me unhappy. Of course, you can use ftok() to generate a unique key. This code is not allmighty, another process under the same user can open the queue and function returns true. But in some situation it could help.

code:

<?
function ipcEXCL($res,$perm)
{
 $pole = msg_stat_queue($res);
 
 if($pole['msg_perm.uid']==posix_getuid() &&
    $pole['msg_perm.gid']==posix_getgid()  &&
    $pole['msg_perm.mode']==$perm  &&
    $pole['msg_stime']==0  &&
    $pole['msg_rtime']==0  &&
    $pole['msg_qnum']==0  &&
    $pole['msg_lspid']==0  &&
    $pole['msg_rspid']==0)
        return true;
 else
        return false;
}

$res=msg_get_queue($key,$perm);

if(ipcEXCL($res,$perm))
   echo "probably I am a creator:";
else
   echo "probably not";
?>
zxd at zhangxiaodong dot net
15-Dec-2004 09:55
#
# require --enable-sysvmsg configure option
#
# see phpinfo() to find how to check
#
joeldg AT listbid.com
02-May-2003 12:10
// Here is an example of working with message queues.
// if you have forked processes, this could be a great way of passing
// out work to them

// create the message queue
// pick a file..
  $key_t = msg_get_queue(ftok("/tmp/php_msgqueue.stat", 'R'),0666 | IPC_CREAT);

    // place two messages on the queue
    if (!msg_send ($key_t, 1, 'This is message #1', true, true, $msg_err))
       echo "Msg not sent because $msg_err\n";
    if (!msg_send ($key_t, 1, 'This is message #2 ', true, true, $msg_err))
       echo "Msg not sent because $msg_err\n";
     
    // lets look at the queue structure 'msg_qnum' is really what we want to see
    // it should be '2'
    print_r(msg_stat_queue($key_t));
   
    // pull off the stack
        if (msg_receive ($key_t, 1, $msg_type, 16384, $msg, true, 0, $msg_error)) {
           if ($msg == 'Quit');
           echo "$msg\n"; // prints 'This is message #1'
        } else {
           echo "Received $msg_error fetching message\n";
        }
    // look at the structure again, ms_qnum should be '1'   
    print_r(msg_stat_queue($key_t));
        if (msg_receive ($key_t, 1, $msg_type, 16384, $msg, true, 0, $msg_error)) {
           if ($msg == 'Quit');
           echo "$msg\n"; // prints 'This is message #2'
        } else {
           echo "Received $msg_error fetching message\n";
        }
   // look at the structure again, ms_qnum should be '0', no more messages on the queue
   print_r(msg_stat_queue($key_t)); 

   // get rid of the queue we created
   msg_remove_queue ($key_t);

msg_queue_exists> <ftok
Last updated: Fri, 14 Nov 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites