ubuntu12.04 use C to write PHP extension Module tutorial

Source: Internet
Author: User
Tags php language php source code svn

The

 php language has a number of extension modules, such as Mbstring, GD, PDO, and so on. Sometimes in order to improve efficiency, you need to use C to implement some of these functions, you can write your own PHP extension module

The system is Ubuntu 12.04, and the version of Apache and php,php has been installed is 5.3.10.   If you encounter permissions issues, it is recommended that you switch to root operation.   1, download source   Check out PHP 5.3.10 source code     code as follows: $ svn checkout https://svn.php.net/repository/php/php-src/ branches/php_5_3_10/    Tips: If you do not have this command, you need to install SVN, in Ubuntu directly using the Apt-get installation is OK:   Code as follows: $ sudo apt-get Install subversion     about PHP source code, if you need more information, you can view the PHP wiki about svn: Https://wiki.php.net/vcs/svnfaq   2, create modules & nbsp A, the source code after checkout, enter the source code ext directory, first with Ext_skel to create a module, the module name is my:   code as follows: $/ext_skel--extname=my     B, enter my module:   Code as follows: $ cd My     C, modify CONFIG.M4 file, find the following:     code is as follows: Dnl Php_arg_with (my, for my support, dnl make sure The comment is aligned:dnl [ --with-my             Include my support])     Remove the previous dnl as follows:     code as follows: Php_arg_with (my, for my support, make sure this comment is aligned: [ --with -my             Include my support])   &NBSp Then save the file.   Tips: If you need to test the correct changes, you can use the PHP my.php to test:   Code as follows: $ php my.php confirm_my_compiled   congratulations! You have successfully modified EXT/MY/CONFIG.M4. Module my are now compiled into PHP.       The above confirm_my_compiled is the module default function, after the module is loaded, you can call this function.   3, compile module   or in the directory of my module execute the following command:   code is as follows: $ phpize $/configure $ make $ made install     compiles successfully, prompts this Kind of information:     Code as follows: Installing shared extensions:/usr/lib/php5/20090626+lfs/    Indicates that the module has been compiled and completed, and copied to the PHP module directory.   Tips: If the phpize command is not found, you need to install the Php5-dev, under Ubuntu directly using Apt-get installation on the OK.   Code as follows: $ apt-get Install Php5-dev     4, loading module   Edit file:   Code as follows: $ Vim/etc/php5/conf.d/my.ini &nbsp ;   Add the following, which means loading the my.so module and saving it.     Code as follows: extension=my.so     Restart Apache   code as follows: $/etc/init.d/apache2 restart     in the Web ring Environment, you can use Phpinfo to see if the My module is loaded. Terminals can use Php-i | Less view.   5, write test procedures   If the above is done smoothly, then the My module is loaded in, the My module's default method Confirm_my_compiThe LEDs can also be invoked. Write PHP test file:     code as follows: Echo confirm_my_compiled ("Hello");     Execute the test file, if you see the output below, then it succeeds.   Code as follows: congratulations! You have successfully modified EXT/MY/CONFIG.M4. Module Hello is now compiled into PHP.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.