> 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php