From b9d505bf5257457d646c1ca16a36652ff25a0243 Mon Sep 17 00:00:00 2001
From: Emiel Bruijntjes
- You probably already know that native PHP extensions are compiled into *.so
+ You probably know that native PHP extensions are compiled into *.so
files on unix-like systems, and *.dll files in Windows environments, and that
the global php.ini file holds a list of all extensions available on your system.
This means that if you're building your own extension, you are also going to
create such a *.so or *.dll file and you have to update the PHP
configuration file so that your own extension is loaded by PHP.
- If for one reason or another you can not find the PHP configuration file(s)
- on your system, you can run the following command from the command line:
-
-How does PHP load its extensions?
Where to find your PHP configuration files?
-
-php --ini
-
-
- This will output a list of all configuration files that are loaded by PHP. - Extensions are enabled by adding "extension=name.so" lines to the - configuration file - where 'name' should of course be replaced by the name of - your extension. A default PHP installation already comes with many default - extensions, so in the configuration file(s) on your system you will certainly - find a number of these "extension=name.so" lines. -
-- The extension lines either take an absolute path ("extension=/path/to/extension.so") - or a relative path ("extension=extension.so"). If you'd like to use relative - paths, you must make sure that you've copied your extension *.so file to the - default extension directory, so that PHP can find it. To find out this default - extension directory, use the following command line instruction: -
--
-php -i|grep extension_dir -- -
- The extension dir often has the form /usr/lib/php5/20121212 - or a different - date string depending on the PHP version you use. -
-Before we explain how you can create your own extension, we first explain - what PHP does to load an extension. When PHP starts, it loads the *.ini configuration - file(s) that we just described and for each "extension=name.so" line in these - files, it opens the appropriate library, and calls the "get_module()" - function from it. Each extension library (your extension too) must therefore - define and implement this "get_module()" C function. The function is called by - PHP right after the library is loaded (and thus way before pageviews are handled), - and it should return a memory address that points to a structure that holds information - about all functions, classes, variables and constants that are made available - by the extension. + what PHP does to load an extension. When PHP starts, it loads the *.ini + configuration file(s) from its configuration directory and for each + "extension=name.so" line in these config files, it opens the appropriate + library, and calls the "get_module()" function from it. Each extension library + (your extension too) must therefore define and implement this "get_module()" + function. The function is called by PHP right after the library is loaded + (and thus way before pageviews are handled), and it should return a memory + address that points to a structure that holds information about all functions, + classes, variables and constants that are made available by the extension.
The structure that the get_module() returns is defined in the header files of -- cgit v1.2.3