The PHP program has been written for a long time, and naturally knows the functions he provides, and he offers a lot of features that really feel good, but sometimes it turns out that PHP lacks some functionality and always produces ideas for adding some custom functionality to PHP. Over time, finally today can not hold up, began to study how to add.
Download a PHP source code package, here is the use of PHP 4.0.5 version, decompression will see the root directory of PHP will have readme.ext_skel such a file, open a specific reading, found a very useful tool, this tool can help you build an empty PHP extension, Then you add the corresponding code to the inside to complete your own extension of the function. Here's how to use this tool.
First transfer your directory to the PHP directory under the EXT directory, if you only need a basic extension framework, execute the following command:
./ext_skel--extname=module_name
Module_name is the name of the extension module that you can choose from, such as the my_module I chose. After executing the tool will automatically in the EXT directory to create your choice of module_name name directory, which has generated the relevant code, which only need to adjust the Config.m4 file in the three lines of comments can normally compile with this custom extension module PHP. You can get it by doing the following in the root directory of PHP.
./buildconf
./configure--enable-module_name
Make
Let me show you the whole process of building the My_module extension framework, and in order to be more effective, we're going to do a PHP extension that calls this feature in PHP to display the word Hello World in a Web page.
In the Ext directory under the PHP directory, execute the following command
./ext_skel--extname=my_module
Get feedback results:
Creating directory My_module
Creating basic Files:config.m4 makefile.in. Cvsignore my_module.c php_my_module.h tests/001.phpt my_module.php [done].
To use your new extension, you'll have to execute the following steps:
1. $ cd ...
2. $ VI EXT/MY_MODULE/CONFIG.M4
3. $/buildconf
4. $/configure--[with|enable]-my_module
5. $ make
6. $/php-f ext/my_module/my_module.php
7. $ VI ext/my_module/my_module.c
8. $ make
Repeat steps 3-6 until you are satisfied with EXT/MY_MODULE/CONFIG.M4 and
Step 6 confirms the Your module is compiled into PHP. Then, start writing
Code and repeat the last two steps as often as necessary.
Add the following code at the end of the file
Php_function (Say_hello)
{
zend_printf ("Hello worldn");
}
Save file Exit
VI php_my_module.h
php_function in file (confirm_my_module_compiled); Line before adding the following code
Php_function (Say_hello);
Save file Exit
Return to the root directory of PHP, and execute the following command
./buildconf
./configure--enable-my_module
make< br>
If all goes well, we have now compiled the extension module my_module into PHP. We write the following code to test the
Say_hello ();
Save file as say_hello.php
runs under the root directory of PHP
./php