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 . 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
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?
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
]) ], [])
--
Regards,
Ruslan Osmanov