| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <title>Chapter 22. Berkeley DB Extensions</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 | <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 | <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 11 | <link rel="prev" href="tcl_faq.html" title="Tcl FAQ" /> |
| 12 | <link rel="next" href="ext_perl.html" title="Using Berkeley DB with Perl" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Chapter 22. |
| 22 | Berkeley DB Extensions |
| 23 | </th> |
| 24 | </tr> |
| 25 | <tr> |
| 26 | <td width="20%" align="left"><a accesskey="p" href="tcl_faq.html">Prev</a> </td> |
| 27 | <th width="60%" align="center"> </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="ext_perl.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="chapter" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title"><a id="ext"></a>Chapter 22. |
| 38 | Berkeley DB Extensions |
| 39 | </h2> |
| 40 | </div> |
| 41 | </div> |
| 42 | </div> |
| 43 | <div class="toc"> |
| 44 | <p> |
| 45 | <b>Table of Contents</b> |
| 46 | </p> |
| 47 | <dl> |
| 48 | <dt> |
| 49 | <span class="sect1"> |
| 50 | <a href="ext.html#ext_mod">Using Berkeley DB with Apache</a> |
| 51 | </span> |
| 52 | </dt> |
| 53 | <dt> |
| 54 | <span class="sect1"> |
| 55 | <a href="ext_perl.html">Using Berkeley DB with Perl</a> |
| 56 | </span> |
| 57 | </dt> |
| 58 | <dt> |
| 59 | <span class="sect1"> |
| 60 | <a href="ext_php.html">Using Berkeley DB with PHP</a> |
| 61 | </span> |
| 62 | </dt> |
| 63 | </dl> |
| 64 | </div> |
| 65 | <div class="sect1" lang="en" xml:lang="en"> |
| 66 | <div class="titlepage"> |
| 67 | <div> |
| 68 | <div> |
| 69 | <h2 class="title" style="clear: both"><a id="ext_mod"></a>Using Berkeley DB with Apache</h2> |
| 70 | </div> |
| 71 | </div> |
| 72 | </div> |
| 73 | <p>A mod_db4 Apache module is included in the Berkeley DB distribution, providing |
| 74 | a safe framework for running Berkeley DB applications in an Apache 1.3 |
| 75 | environment. Apache natively provides no interface for communication |
| 76 | between threads or processes, so the mod_db4 module exists to provide |
| 77 | this communication.</p> |
| 78 | <p>In general, it is dangerous to run Berkeley DB in a multiprocess system |
| 79 | without some facility to coordinate database recovery between processes |
| 80 | sharing the database environment after application or system failure. |
| 81 | Failure to run recovery after failure can include process hangs and an |
| 82 | inability to access the database environment. The mod_db4 Apache module |
| 83 | oversees the proper management of Berkeley DB database environment resources. |
| 84 | Developers building applications using Berkeley DB as the storage manager |
| 85 | within an Apache module should employ this technique for proper resource |
| 86 | management.</p> |
| 87 | <p>Specifically, mod_db4 provides the following facilities:</p> |
| 88 | <div class="orderedlist"> |
| 89 | <ol type="1"> |
| 90 | <li>New constructors for <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> and <a href="../api_reference/C/db.html" class="olink">DB</a> handles, which install |
| 91 | replacement open/close methods.</li> |
| 92 | <li>Transparent caching of open <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> and <a href="../api_reference/C/db.html" class="olink">DB</a> handles.</li> |
| 93 | <li>Reference counting on all structures, allowing the module to detect the |
| 94 | initial opening of any managed database and automatically perform recovery.</li> |
| 95 | <li>Automatic detection of unexpected failures (segfaults, or a module |
| 96 | actually calling exit() and avoiding shut down phases), and automatic |
| 97 | termination of all child processes with open database resources to |
| 98 | attempt consistency.</li> |
| 99 | </ol> |
| 100 | </div> |
| 101 | <p>mod_db4 is designed to be used as an alternative interface to Berkeley DB. To |
| 102 | have another Apache module (for example, mod_foo) use mod_db4, do not |
| 103 | link mod_foo against the Berkeley DB library. In your mod_foo makefile, you |
| 104 | should:</p> |
| 105 | <pre class="programlisting">#include "mod_db4_export.h"</pre> |
| 106 | <p>and add your Apache include directory to your CPPFLAGS.</p> |
| 107 | <p>In mod_foo, to create a mod_db4 managed <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> handle, use the |
| 108 | following:</p> |
| 109 | <pre class="programlisting">int mod_db4_db_env_create(DB_ENV **dbenvp, u_int32_t flags);</pre> |
| 110 | <p>which takes identical arguments to <a href="../api_reference/C/envcreate.html" class="olink">db_env_create()</a>.</p> |
| 111 | <p>To create a mod_db4 managed <a href="../api_reference/C/db.html" class="olink">DB</a> handle, use the following:</p> |
| 112 | <pre class="programlisting">int mod_db4_db_create(DB **dbp, DB_ENV *dbenv, u_int32_t flags);</pre> |
| 113 | <p>which takes identical arguments to <a href="../api_reference/C/dbcreate.html" class="olink">db_create()</a>.</p> |
| 114 | <p>Otherwise the API is completely consistent with the standard Berkeley DB |
| 115 | API.</p> |
| 116 | <p>The mod_db4 module requires the Berkeley DB library be compiled with C++ |
| 117 | extensions and the MM library. (The MM library provides an abstraction |
| 118 | layer which allows related processes to share data easily. On systems |
| 119 | where shared memory or other inter-process communication mechanisms are |
| 120 | not available, the MM library emulates them using temporary files. MM |
| 121 | is used in several operating systems to provide shared memory pools to |
| 122 | Apache modules.)</p> |
| 123 | <p>To build this apache module, perform the following steps:</p> |
| 124 | <pre class="programlisting">% ./configure --with-apxs=[path to the apxs utility] \ |
| 125 | --with-db4=[Berkeley DB library installation directory] \ |
| 126 | --with-mm=[libmm installation directory] |
| 127 | % make |
| 128 | % make install</pre> |
| 129 | <p>Post-installation, modules can use this extension via the functions |
| 130 | documented in $APACHE_INCLUDEDIR/mod_db4_export.h.</p> |
| 131 | </div> |
| 132 | </div> |
| 133 | <div class="navfooter"> |
| 134 | <hr /> |
| 135 | <table width="100%" summary="Navigation footer"> |
| 136 | <tr> |
| 137 | <td width="40%" align="left"><a accesskey="p" href="tcl_faq.html">Prev</a> </td> |
| 138 | <td width="20%" align="center"> </td> |
| 139 | <td width="40%" align="right"> <a accesskey="n" href="ext_perl.html">Next</a></td> |
| 140 | </tr> |
| 141 | <tr> |
| 142 | <td width="40%" align="left" valign="top">Tcl FAQ </td> |
| 143 | <td width="20%" align="center"> |
| 144 | <a accesskey="h" href="index.html">Home</a> |
| 145 | </td> |
| 146 | <td width="40%" align="right" valign="top"> Using Berkeley DB with Perl</td> |
| 147 | </tr> |
| 148 | </table> |
| 149 | </div> |
| 150 | </body> |
| 151 | </html> |