This section briefly introduces PHP extension development experience. Environment: PHP5.2.14CentOS5.5 Step 1: build extension skeleton cdphp-5.2.14ext.ext_skel-extnamelaiwenhui Step 2: modify compilation parameters cdphp-5.2.14extlaiwenhuiviconfig. environment: PHP 5.2.14 CentOS 5.5
Step 1: Create an extension skeleton
Cd php-5.2.14/ext
./Ext_skel-extname = laiwenhui
Step 2: modify compilation parameters
Cd php-5.2.14/ext/laiwenhui
Vi config. m4
Remove
PHP_ARG_ENABLE (laiwenhui, whether to enable laiwenhui support,
[-- Enable-laiwenhui Enable laiwenhui support])
Dnl before two rows
After modification:
The code is as follows:
Dnl Otherwise use enable:
PHP_ARG_ENABLE (laiwenhui, whether to enable laiwenhui support,
Dnl Make sure that the comment is aligned:
[-- Enable-laiwenhui Enable laiwenhui support])
Step 3: write code
Vim php_laiwenhui.h
Add PHP_FUNCTION (confirm_laiwenhui_compiled); followed by PHP_FUNCTION (test );
After adding:
PHP_FUNCTION (confirm_laiwenhui_compiled);/* For testing, remove later .*/
PHP_FUNCTION (test );
Then
Vim laiwenhui. c
Add PHP_FE (test, NULL) to PHP_FE (confirm_laiwenhui_compiled, NULL)
After adding:
The code is as follows:
Zend_function_entry laiwenhui_functions [] = {
PHP_FE (confirm_laiwenhui_compiled, NULL)/* For testing, remove later .*/
PHP_FE (test, NULL)/* For testing, remove later .*/
{NULL, NULL, NULL}/* Must be the last line in laiwenhui_functions [] */
};
Add the following code at the end of the file:
The code is as follows:
PHP_FUNCTION (test)
{
Char * arg = "This my first extention !";
Int len;
Char * strg;
Len = spprintf (& strg, 0, "% s \ n", arg );
RETURN_STRINGL (strg, len, 0 );
}
Step 4: compile the code
The code is as follows:
Cd php-5.2.6/ext/laiwenhui
/Opt/module/php/bin/phpize
./Configure-with-php-config =/opt/module/php/bin/php-config
Make
Make install
My PHP installation path is/opt/module/php
This will generate a file/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui. so
Edit the PHP configuration file php. ini and add extensions:
Vim php. ini
Added extension = laiwenhui. so in the [PHP] module.
; Extension = php_zip.dll
Extension = laiwenhui. so
Modify extension_dir in the php. ini file to this directory:
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"
; Directory in which the loadable extensions (modules) reside.
Extension_dir = "/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613 /"
Step 5: check the installation result
1. restart apache or php-fpm
2. check whether laiwenhui extensions are included in/opt/module/php/bin/php-m.
Step 6: execute the test code
Create test. php in the root directory of the website
Vim test. php
The code is as follows:
Echo test ();
?>
The result is: This my first extention!
If you can successfully complete the above steps, congratulations on completing the first extension.
The above is a simple step to expand PHP. For more information, see:
Objective 5.2.14 CentOS 5.5 Step 1: build the extension skeleton cd php-5.2.14/ext./ext_skel-extname = laiwenhui Step 2: modify the compilation parameters cd php-5.2.14/ext/laiwenhui vi config ....