Hi Wez,
this patch that adds a msg_queue_exists() to ext/sysvmsg. Currently there is no way to tell wether msg_get_queue() will create or just a attach to a queue.

It would be great to see this function in the next PHP release.

Benjamin
diff -u php-5.2.1/ext/sysvmsg/php_sysvmsg.h 
php-5.2.1-patched/ext/sysvmsg/php_sysvmsg.h
--- php-5.2.1/ext/sysvmsg/php_sysvmsg.h 2007-01-08 23:34:07.000000000 +0100
+++ php-5.2.1-patched/ext/sysvmsg/php_sysvmsg.h 2007-03-01 15:51:28.000000000 
+0100
@@ -48,6 +48,7 @@
 PHP_FUNCTION(msg_set_queue);
 PHP_FUNCTION(msg_send);
 PHP_FUNCTION(msg_receive);
+PHP_FUNCTION(msg_queue_exists);
 
 typedef struct {
        key_t key;
diff -u php-5.2.1/ext/sysvmsg/sysvmsg.c php-5.2.1-patched/ext/sysvmsg/sysvmsg.c
--- php-5.2.1/ext/sysvmsg/sysvmsg.c     2007-01-17 09:25:32.000000000 +0100
+++ php-5.2.1-patched/ext/sysvmsg/sysvmsg.c     2007-03-01 15:51:28.000000000 
+0100
@@ -72,6 +72,7 @@
        PHP_FE(msg_remove_queue,                        NULL)
        PHP_FE(msg_stat_queue,                          NULL)
        PHP_FE(msg_set_queue,                           NULL)
+       PHP_FE(msg_queue_exists,                        NULL)
        {NULL, NULL, NULL}      /* Must be the last line in sysvmsg_functions[] 
*/
 };
 /* }}} */
@@ -206,6 +207,26 @@
 }
 /* }}} */
 
+
+/* {{{ proto bool msg_queue_exists(int key)
+   Check wether a message queue exists */
+PHP_FUNCTION(msg_queue_exists)
+{
+    long key;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == 
FAILURE)     {
+               return;
+       }
+
+    if (msgget(key, 0) < 0) {
+        RETURN_FALSE;
+    }
+
+    RETURN_TRUE;
+}
+/* }}} */
+
+
 /* {{{ proto resource msg_get_queue(int key [, int perms])
    Attach to a message queue */
 PHP_FUNCTION(msg_get_queue)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to