First, build PHP environment
Download PHP 5.2.6 source code and unzip
Compile and install, build PHP environment
Second, create an extension project
Enter the source directory
CD php5.2.6/ext/
./ext_skel--extname=my_ext
Create a project named My_ext that will eventually generate my_ext.so
Third, change the configuration and program
$ VI EXT/MY_EXT/CONFIG.M4
Depending on your own choice, you will
DNL Php_arg_with (My_ext, for my_ext support,
DNL Make sure, the comment is aligned:
DNL [--with-my_ext Include my_ext support])
Modified into
Php_arg_with (My_ext, for my_ext support,
Make sure, the comment is aligned:
[--with-my_ext Include My_ext support])
or the
DNL php_arg_enable (My_ext, whether to ENABLE My_ext support,
DNL Make sure, the comment is aligned:
DNL [--enable-my_ext enable my_ext support])
Modified into
Php_arg_enable (My_ext, whether to ENABLE My_ext support,
Make sure, the comment is aligned:
[--enable-my_ext enable my_ext support])
$ VI ext/my_ext/php_my_ext.h
Will
Php_function (confirm_my_ext_compiled); /* For testing, remove later. */
Change to
Php_function (Say_hello);
$ VI ext/my_ext/my_ext.c
Will
Zend_function_entry php5cpp_functions[] = {
Php_fe (confirm_my_ext_compiled, NULL)/* For testing, remove later. */
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] */
};
Change to
Zend_function_entry php5cpp_functions[] = {
Php_fe (Say_hello, NULL)
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] */
};
Added at the end:
Php_function (Say_hello)
{
zend_printf ("Hello world\n");
}
Four, compiling
$ CD My_ext
$/usr/local/php/bin/phpize
PS: If it appears: Cannot find autoconf .... Error message, you will need to install autoconf (the installation process is slightly)
$./configure--with-php-config=/usr/local/php/bin/php-config
$ make
This will compile the my_ext/modules/my_ext.so
Five, configuration php.ini
Put the my_ext.so into /usr/local/php/ext/Directory
$ VI php.ini
The modifications are added as follows:
Extension_dir = '/usr/local/php/ext/'
extension=my_ext.so
Six, Test
$ VI test.php
Say_hello ();
?>
$/usr/local/php/bin/php test.php
Hello world.
It's done.
PS: If you have any questions please leave a message, we discuss together
http://www.bkjia.com/PHPjc/319688.html www.bkjia.com true http://www.bkjia.com/PHPjc/319688.html techarticle First, build PHP environment download PHP 5.2.6 source code and unzip the installation, build PHP environment Two, create extension project into the source directory CD php5.2.6/ext/./ext_skel--extname=my_ext Create name ...