Step 1: Create an extension skeleton. The [html] cd/usr/local/src/php-5.3.6/ext /. /ext_skel -- extname = laiwenhuicd/usr/local/src/php-5.3.6/ext /. /ext_skel -- extname = laiwenhui Step 2: modify the compilation parameters. [Html] v
Step 1: Create an extension skeleton.
[Html]
Cd/usr/local/src/php-5.3.6/ext/
./Ext_skel -- extname = laiwenhui
Cd/usr/local/src/php-5.3.6/ext/
./Ext_skel -- extname = laiwenhui Step 2: modify the compilation parameters.
[Html] view plaincopyprint? Cd php-5.3.6/ext/laiwenhui
Vi config. m4
Cd php-5.3.6/ext/laiwenhui
Remove vi config. m4
PHP_ARG_ENABLE (laiwenhui, whether to enable laiwenhui support,
[-- Enable-laiwenhui Enable laiwenhui support])
Dnl before two rows
After modification:
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
[Html]
Vim php_laiwenhui.h
Vim php_laiwenhui.h
In
PHP_FUNCTION (confirm_laiwenhui_compiled );
Add a line later
PHP_FUNCTION (test );
[Html]
Vim laiwenhui. c
Vim laiwenhui. c
In
PHP_FE (confirm_laiwenhui_compiled, NULL)
Add
PHP_FE (test, NULL)
** Add the following code at the end of the file :**
[Html]
PHP_FUNCTION (test)
{
Char * arg = "This is my first extention! ";
Int len;
Char * strg;
Len = spprintf (& strg, 0, "% s \ n", arg );
RETURN_STRINGL (strg, len, 0 );
}
PHP_FUNCTION (test)
{
Char * arg = "This is my first extention! ";
Int len;
Char * strg;
Len = spprintf (& strg, 0, "% s \ n", arg );
RETURN_STRINGL (strg, len, 0 );
} Step 4: compile the code
[Html]
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Make install
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Make install
My PHP installation path is/usr/local/php
This will generate a file/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui. so
Edit the PHP configuration file php. ini and add extensions:
[Html]
Vim php. ini
Vim php. ini added in the [PHP] module:
[Html]
Extension = laiwenhui. so
Extension = laiwenhui. so modify extension_dir in the php. ini file to this directory:
[Html]
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"
Step 5: check the installation result
1. restart php-fpm, ngixn
2./use/local/php/bin/php-m
Check whether the laiwenhui extension exists.
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 is my first extention!
If you can successfully complete the above steps, congratulations on completing the first extension.