On the development of PHP extension

Source: Internet
Author: User

February 26, 2015 15:44:41

Reason: Want to use PHP to implement a filter algorithm, which to use in place operation, but PHP's built-in int type does not give force, can not support the bit operation of large integers

Once the data is too large, it becomes a floating-point number, floating-point numbers cannot participate in bit operations ... Also tried Nodejs, Redis is not. With Java, you have to take the environment.

Just want to use the PHP extension, C to achieve

The first step: using PHP commands to automatically generate the extension framework

Enter the source code directory of PHP and enter the EXT directory

./ext_skel--extname=zzbbloom

Step Two: Modify the framework to add your own function code

The frame that was built in the previous step is actually a folder named Zzbbloom, and in/path/to/php/src/ext/zzbbloom/, go to the folder

1) Edit the Config.m4 file (the "DNL" at the beginning of each line of the file is the comment) and find the php_arg_enable (Zzbbloom, ...). In these lines, remove the DNL string from the front:

1 php_arg_enable (Zzbbloom, whether to ENABLE zzbbloom support,2     [  --enable-zzbbloom           enable zzbbloom support])

2) edit zzbbloom.h zzbbloom.c file add your own function (can also be automatically generated by the framework function, confirm_zzbbloom_compiled ())

Reference: Http://www.jb51.net/article/16791.htm http://www.open-open.com/lib/view/open1340585955030.html

Step three: Compiling

First go inside the generated framework directory, then execute the phpize command, then execute the./configure command, final make, make install

1 cd path/to/php/srccode/ext/zzbbloom/2 /usr/local/php/bin/pphpize//This command generates configure Makefile and other documents 3 ./configure--with-php-config=/usr/local/php/bin/php-config4  make5makeinstall

Fourth step: Restart PHP-FPM, Nginx

Reference: http://www.cnblogs.com/iLoveMyD/p/4301429.html

Fifth Step: Test

1 Var_dump (Get_loaded_extensions ()); 2 var_dump (Get_extension_funcs ('zzbbloom')); 3 echo confirm_zzbbloom_compiled (' my first php extension, haha haha ');

On the development of PHP extension

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.