httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ras...@lerdorf.on.ca (Rasmus Lerdorf)
Subject Re: apache/linux modules
Date Tue, 03 Feb 1998 05:40:08 GMT
> > > Obviously, the rest of it is correct; you need a standard name, or some
> > > way of extracting the information in another way. A good way might be for
> > > shared modules to all use the same name for their module structure. Then
> > > the loading module can just dlsym() that name, and it will always be
> > > there. This is how ISAPI extensions work, for example.
> > 
> > This is also how PHP modules work.  Or close to it at least.  
> 
> What if a PHP module wants to load a module?  Is there an API for
> that?  <g>

Of course!  One of the main reasons for the PHP rewrite was to make it
easier to build PHP modules.  Yes, it sounds a bit weird, since PHP is
itself a module, but nothing stops me from doing it, and it works very
well.  I have loaded PHP dynamically into Apache, and then from there
loaded mysql and snmp PHP modules dynamically into PHP on a per-script
basis.  

For example, you can write a page that looks something like:

<html>
<? 
   require "constants.inc";
   dl("snmp.so");
   dl("mysql.so");
   $desc = snmpget($ip,$community,$mib2.".system.sysDescr.0");
   mysql_pconnect($host,$user,"") or die("Unable to connect to DB");
   mysql_select_db($db) or die("Unable to select database");
   $result = mysql_query("update table set host='$desc' where entry=0");
?>   
</html>

This little bit of code would dynamically load up both snmp and mysql,
fetch a system description field through snmp and insert it into MySQL. 

And yes, there is an API for writing PHP modules.  The documentation on it
is improving rapidly too.

-Rasmus


Mime
View raw message