Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19763 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27500 invoked by uid 1010); 27 Oct 2005 17:18:37 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 27485 invoked from network); 27 Oct 2005 17:18:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2005 17:18:37 -0000 X-Host-Fingerprint: 69.12.155.130 69-12-155-130.dsl.static.sonic.net Linux 2.4/2.6 Received: from ([69.12.155.130:2007] helo=pigeon.alphaweb.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id B6/2D-22886-DEB01634 for ; Thu, 27 Oct 2005 13:18:37 -0400 Received: from localhost ([127.0.0.1] helo=peiscg33m) by pigeon.alphaweb.net with smtp (Exim 4.10) id 1EVAel-0007HC-00; Thu, 27 Oct 2005 09:31:11 -0700 Message-ID: <005a01c5db1a$755e63c0$5c8be5a9@ohr.berkeley.edu> Reply-To: "Sara Golemon" To: "Marco Bambini" Cc: References: <8F6C2463-0FC7-44E6-A633-C06866031910@vampiresoft.com> Date: Thu, 27 Oct 2005 10:18:32 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Subject: Re: Runtime check... From: pollita@php.net ("Sara Golemon") > 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