Re: How do I make a dependency on the sockets extension?

From: Date: Fri, 06 Sep 2013 09:35:41 +0000
Subject: Re: How do I make a dependency on the sockets extension?
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-11020@lists.php.net to get a copy of this message
On Fri, Sep 6, 2013 at 11:02 AM, Ruslan Osmanov <rrosmanov@gmail.com> wrote: > Hi, > > I wonder what is the right way to make a dependency on > another extension. > > Particularly, in my ext. I use PHPAPI php_sockets_le_socket() function > and php_socket structure both declared in ext/sockets/php_sockets.h. > > The function should be resolved at run-time, and I might even declare > some extern prototype. But I also need the php_socket struct. Obviously, > I have to include ext/sockets/php_sockets.h: > > #if PHP_VERSION_ID >= 50301 && (HAVE_SOCKETS || > defined(COMPILE_DL_SOCKETS)) > # include <ext/sockets/php_sockets.h> > # define PHP_EVENT_SOCKETS_SUPPORT > #endif > > Sockets extension is optional, so I do the following in config.m4: > PHP_ADD_EXTENSION_DEP(event, sockets, true) > and the following in C: > static const zend_module_dep event_deps[] = { > ZEND_MOD_OPTIONAL("sockets") > {NULL, NULL, NULL} > }; > > However, it won't work if the sockets extension is built separately, > for instance. Please, give me advice, what should I reply to this bug: > > https://bugs.php.net/bug.php?**id=65597<https://bugs.php.net/bug.php?id=65597>. > Would it be fixed, if I make > "sockets" required? > If the socket extension is not loaded in, you'll end up with execution errors such as "cant find symbol foo.bar", and the process will end. I think you have two options : - Make ext/socket a ZEND_MOD_REQUIRED , but beware that any installation not having ext/sockets simply wont be able to load your extension - Or : check at runtime if ext/socket is available, only for the functions of yours that require it. You can do this is in lots of ways, such as checking for ext/socket into the module_registry ( http://lxr.php.net/xref/PHP_5_4/Zend/zend_API.c#36) or check for an ext/socket function in the function table. Julien.Pauli

« previous php.pecl.dev (#11020) next »