Original: CentOS PHP extension Development process
First, install PHP
CentOS default Yum Install PHP version is 5.3, many PHP framework requires more than 5.4 version, this time can not directly use Yum install PHP need to change the Yum source first.
1.start Remi Source
1 # CD/tmp2wget http://rpms.famillecollet.com/enterprise/ remi-release-6.rpm3wget http://mirrors.sohu.com/fedora-epel/6/i386/ epel-release-6-8.noarch.rpm
2.RPM Installation
# RPM-UVH remi-release-6. RPM epel-release-6-8. noarch.rpm
3, install >=5.4 above PHP
Yum Install PHP
Second, the expansion of development 1, PHP source code download
wget http://cn2.php.net/distributions/php-5.4.43.tar.gz
VZXF php-5.4.42.tar.gz
Note that the version you download here is consistent with the version of PHP installed in the system, and PHP looks at the version command
Php-v
My system installation is 5.4.
2, Installation Phpize
(Phpize is used to extend the PHP extension module, through the phpize can build PHP plug-in module)
Yum Install phpize
3. Ext_skel Tools
Ext_skel is a PHP write extension that provides an easy-to-use "automated build system" that he can easily build with PHP extensions. This tool is the PHP Source tool is located in the source of the Ext directory
# cd/php-5.4. /ext#. /ext_skel--extname = Myext
After you perform the build extension, an Myext folder is automatically created under Ext.
# CD myext# vim CONFIG.M4
Put the Config.m4 file inside
for Myext Support,dnl Make sure, the comment is aligned:dnl [ --with-myext Include myext support])
Modified into
for myext support,[ --with-myext Include myext support])
4, write a simple test C extension
Modify Php_myext.h, see Php_function (confirm_myext_compiled); This is the extension function declaration section, you can add a
Php_function (confirm_myext_compiled); Php_function (Myext_helloworld);
Then modify the myext.c, which is the implementation part of the extension function.
Const zend_function_entry myext_functions[] = { Php_fe (confirm_myext_compiled, NULL) / ** /Php_fe (Myext_helloworld, NULL) php_fe_end /* */};
The code for this is to register the function pointer to the Zend engine, adding a line of Php_fe (Myext_helloworld, NULL) (with no semicolon behind).
Add Myext_helloworld execution code at the end of the myext.c.
php_function (Myext_helloworld) { char
*arg = NULL; int Arg_len, Len; char *STRG; if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, " s " , &arg, &arg_len) = = FAILURE) { return ; } php_printf ( hello world!\n Span style= "color: #800000;" > " ); retrun_true;}
Zend_parse_parameters is used to accept the parameters that are passed into PHP, and the RETURN_XXX macro is used to return the data to PHP.
5. Compile and install PHP extensions
# phpize#. /configure# make# make test# make install
Jump to PHP extension file plus you can see a lot of myext.so files.
# cd/usr/lib64/php//etc/php.ini
Add a line Extension
Extension=myext.so
To see if the extension was successfully installed
Php-m
See a myext.so extension, OK, and then we'll see if our custom function executes correctly.
Execute Php-r "myext_helloworld (' Test ');", Output Hello world!
Third, little sentiment
Echosong before the window to do a variety of PHP extension problems, the latest found liunx PHP extension more convenient than window. If you want to do PHP extension friends are recommended to get started directly liunx under development.
In addition feel liunx C development, especially with the operating system to communicate a variety of smooth. O (∩_∩) o~
CentOS PHP Extension Development process