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

From: Date: Sun, 08 Sep 2013 13:05:07 +0000
Subject: Re: How do I make a dependency on the sockets extension?
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-11033@lists.php.net to get a copy of this message
On 09/08/2013 05:26 PM, Johannes Schlüter wrote:
On Sun, 2013-09-08 at 16:27 +0500, Ruslan Osmanov wrote:
Okay, I've figured out that PHP_ADD_EXTENSION_DEP is supposed to be used at the configuration time only. The HAVE_SOCKETS symbol is defined in <main/php_config.h>, if PHP is built with --enable-sockets option. But if sockets is built as a separate package, then we have no HAVE_SOCKETS symbol at compilation time. I guess some OS distributions, having no support of per-package configuration, provide separate packages like "php-sockets". Thus, making "sockets" required doesn't solve the issue at all. Probably I can fix it by defining HAVE_SOCKETS manually in my config.m4: if test "$PHP_EVENT_SOCKETS" != "no"; then
      AC_CHECK_HEADERS([$phpincludedir/ext/sockets/php_sockets.h], ,
        [
          AC_MSG_ERROR([Couldn't find
$phpincludedir/sockets/php_sockets.h. Please check if sockets extension installed])
        ]
      )
      PHP_ADD_EXTENSION_DEP(event, sockets)
      AC_DEFINE(PHP_EVENT_SOCKETS, 1, [Whether sockets extension is
      dnl A hack for distros installing sockets ext. separately.
      AC_DEFINE(HAVE_SOCKETS, 1, [Whether sockets extension is enabled])
fi
Compile-time checks for other extensions are only relevant for static builds. Once you go to shared extensions the availability at compile time tells *nothing* about runtime. (An extension might be installed only for one SAPI or PHP might run CLI with -n or ...) You can check for the required headers in your m4 and prevent building the extension if not available but aside from that any further check gains nothing practical. johannes
Let's note, that no code can use sockets' API until HAVE_SOCKETS defined. Thus, sockets' API is not available, if PHP is built with --disable-sockets. Then it doesn't matter whether we installed sockets separately. The header code is just not available. So what should we do? The only answer I see is to define HAVE_SOCKETS ourselves manually. Isn't it? It even might be normal, if we had a macro able to determine whether sockets ext. is installed. Let's imagine the pear installer modified/added some C header file which is included in some common header like main/php_config.h. Then we might use some macro which might try to include/compile and eventually determine whether we have sockets extension installed. Different ini-files. Yes, it is a problem. Another one. But we already have such kind of run-time check for the required extensions. -- Ruslan Osmanov

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