# Runtime check...

- Thread: https://externals.io/message/19762
- Original archive: https://news-web.php.net/php.internals/19762
- Started by Marco Bambini on 2005-10-27T16:28:23+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19762 — Marco Bambini — 2005-10-27T16:28:23+00:00

URL: https://externals.io/message/19762#19762

I have developed a php extension that requires zlib in order to works  
fine.
The problem is that if someone have compiled php without zlib support  
my extension just crashed when it tries to use some zlib routines.

I wonder if there is a way to check at runtime (or better at startup  
in the PHP_MINIT_FUNCTION) if php has been compiled with zlib support  
so I can gracefully reports a WARNING...

Thanks,
Marco Bambini

---

## #19763 — Sara Golemon — 2005-10-27T17:18:32+00:00

URL: https://externals.io/message/19762#19763 · In reply to: #19762

> I have developed a php extension that requires zlib in order to works
> fine.
> The problem is that if someone have compiled php without zlib support
> my extension just crashed when it tries to use some zlib routines.
>
> I wonder if there is a way to check at runtime (or better at startup
> in the PHP_MINIT_FUNCTION) if php has been compiled with zlib support
> so I can gracefully reports a WARNING...
>
As of PHP 5.1 you can use the module dependency feature which can function
at both buildtime and runtime:

Buildtime:
  PHP_NEW_EXTENSION(mymodule, mymodule.c, $ext_shared)
  ifdef([PHP_ADD_EXTENSION_DEP],
  [
    PHP_ADD_EXTENSION_DEP(mymodule, zlib)
  ])



Runtime:
#if ZEND_EXTENSION_API_NO >= 220050617
static zend_module_dep mymodule_deps[] = {
    ZEND_MOD_REQUIRED("zlib")
    {NULL, NULL, NULL}
};
#endif

zend_module_entry mymodule_module_entry = {
#if ZEND_EXTENSION_API_NO >= 220050617
    STANDARD_MODULE_HEADER_EX, NULL,
    mymodule_deps,
#else
    STANDARD_MODULE_HEADER,
#endif
   ...
};


For earlier versions you can't do the fancy dynamic interdependencies quite
so gracefully, but you can check to see if ZLIB support was compiled in
staticly by testing for the HAVE_ZLIB define:

#ifdef HAVE_ZLIB
    zlib_specific_call(foo, &bar);
#else
    do_it_without_zlib(foo, &bar);
#endif


-Sara
