1. The first is to install a good PHP
2. Into the PHP download extract directory under the EXT directory
#cd/root/php-5.3.6/ext
#./ext_skel--EXTNAME=HMC
Description
./ext_skel--extname=module_name
Module_name is the name of the extension module that you can choose from, such as the HMC 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.
3. Modify CONFIG.M4
You can copy the generated module directory to any desired place
Access to the HMC directory
VI CONFIG.M4
To open a CONFIG.M4 file using a text editor
According to your own choice, you will
DNL Php_arg_with (HMC, for HMC support,
DNL Make sure this comment is aligned:
DNL [--WITH-HMC Include HMC support])
Modified into
Php_arg_with (HMC for HMC support,
Make sure this comment is aligned:
[--WITH-HMC Include HMC support])
or to
DNL php_arg_enable (HMC, whether to ENABLE HMC support,
DNL Make sure this comment is aligned:
DNL [--ENABLE-HMC enable HMC support])
Modified into
Php_arg_enable (HMC, whether to ENABLE HMC support,
Make sure this comment is aligned:
[--ENABLE-HMC enable HMC support])
Generally I will choose the latter and then save the exit.
4. Modify the. C and. h file codes
Vi HMC.C
Modify the following code in the file
/* Every user visible function must have a entry in hmc_functions[].
*/
Const Zend_function_entry hmc_functions[] = {
Php_fe (Say_hello, NULL)/* Add a line of code * *
Php_fe (confirm_hmc_compiled, NULL)/* For testing, remove later. */
{null, NULL, NULL}/* must is the last line in hmc_functions[] * *
};
Add the following code at the end of the file
Php_function (Say_hello)
{
zend_printf ("Hello worldn");
}
Save File Exit
VI php_hmc.h
Php_function (confirm_hmc_compiled) in a file, add the following code before a line
Php_function (Say_hello);
Save File Exit
5. Compile and install
#phpize
#./configure--ENABLE-HMC
#make
#make Install
There should be a hmc.so file in the PHP modules directory, and different machine locations will not be the same
6. Modify PHP Configuration
Edit the php.ini and add the extensions:
Add under [PHP] module:
Extension = hmc.so
Restart httpd
#service httpd Restart
7.php Call
Create a c.php file in the corresponding WWW directory
?
Say_hello ();
?>
The browser should then output:
Hello World
8. Debugging
You can enter at the command line
#php –q c.php
Need to enter the current WWW directory
Check to see if the modules are installed with Phpinfo ().
You can also apply the PHP-M command
First Use
#which PHP
Find PHP directory, different machine directory is not the same
#/usr/bin/php-m
9. Functions with Parameters
Vi HMC.C
Modify the last Say_hello function as follows:
Php_function (Say_hello)
{
Zval **yourname;
if (Zend_num_args ()!= 1 | | | ZEND_GET_PARAMETERS_EX (1, &yourname) = = failure)
{
Wrong_param_count;
}
zend_printf ("Hello World,%sn", Z_strval_pp (yourname));
}
Modify c.php to
?
Say_hello ("Qingqing Moon Son");
?>