On Fri, Sep 6, 2013 at 12:04 PM, Ruslan Osmanov <[email protected]> wrote:
> On 09/06/2013 02:35 PM, Julien Pauli wrote: > > On Fri, Sep 6, 2013 at 11:02 AM, Ruslan Osmanov <[email protected]<mailto: >> [email protected]>> 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<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 >> > > Thanks! > > I'll consider checking for presence of sockets in the module registry. > However, I'm afraid it'll influence on performance too much in my case. So > likely I'll make sockets ext. required eventually. > > But, wouldn't it be better to check for sockets' presence only once in the > MINIT phase? > Yes but, ext/socket could get registered after you, so in your own MINIT you wouldn't notice its presence yet. (Extensions are loaded in alpha order, but you shouldn't rely on that). I still have a project of refactoring extension system for 5.6 , one of the feature would be to keep hands on extensions loading order ;-) > > What about AC_TRY_COMPILE? > > AC_TRY_COMPILE([ > #include "ext/sockets/php_sockets.h" > # ifnef PHP_SOCKETS_API > # error PHP_SOCKETS_API is not defined > # endif > ], [ AC_DEFINE(PHP_EVENT_SOCKETS_**SUPPORT, 1, [ whether sockets > available ]) ], []) You can try to compile something, the problem is that you are gonna link against a library which could not be present at runtime. You have no other choice than checking at runtime so , well, with our actual extension system I would say. Julien.Pauli
