C language extension to php under linux_PHP tutorial

WBOY
Release: 2016-07-21 15:48:43
Original
875 people have browsed it

1. Build a php environment
Download the php 5.2.6 source code and unzip it
Compile and install, build a php environment

2. Create an extension project

Enter the source code directory
cd php5.2.6/ext/
./ext_skel --extname=my_ext
Create a project named my_ext, which will eventually generate my_ext.so

Three, change the configuration and program
$ vi ext/my_ext/config.m4

Change

dnl PHP_ARG_WITH(my_ext, for my_ext support,
dnl Make sure that the comment is aligned:

dnl [ --with-my_ext                                                                                                                                                                                                                                               but for my_ext support my_ext support,
Make sure that the comment is aligned:

[ --with-my_ext                 Include my_ext support])
or

dnl PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
dnl Make sure that the comment is aligned:

dnl [ --enable-my_ext Enable my_ext support])
Modify to

PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,

Make sure that the comment is aligned:
[ --enable-my_ext    Enable my_ext support])

$ vi ext/my_ext/php_my_ext.h

Change
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 be the last line in php5cpp_functions[] */
};
change to
zend_function_entry php5cpp_functions[] = {
PHP_FE(say_hello, NULL)
{NULL, NULL, NULL} / * Must be the last line in php5cpp_functions[] */
};

Add at the end:
PHP_FUNCTION(say_hello)
{
zend_printf("hello worldn");
}


Four. Compile

$ cd my_ext$ /usr/local/php/bin/phpizeps: If it appears: Cannot find autoconf. ... error message, you need to install autoconf (the installation process is omitted)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make

My_ext/modules/my_ext.so will be compiled at this time


5. Configure php.ini

Put my_ext.so into /usr/local/ php/ext/directory
$ vi php.ini


Modify and add as follows:
extension_dir = '/usr/local/php /ext/'

extension=my_ext.so
6. Test

$ vi test.php say_hello();
?>

$ /usr/local/php/bin/php test.php
hello world.

then you’re done

ps: If you have any questions, please leave a message and we can discuss it together.


http://www.bkjia.com/PHPjc/319688.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319688.htmlTechArticle 1. Set up a php environment. Download the php 5.2.6 source code and decompress, compile and install it. 2. Build a php environment. 2. Create an extension project Enter the source code directory cd php5.2.6/ext/ ./ext_skel --extname=my_ext Create a name...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template