PHP Learning notes PHP Extension Development tutorial _php Tutorial

Source: Internet
Author: User
PHP extension development is not a thing that all developers will operate, below I will demonstrate a PHP extension development implementation process, you need to enter the reference.

Let's first assume that an extension is required to provide a function called tao_string, whose primary function is to return a character. The corresponding PHP code might be:

The code is as follows Copy Code

function tao_string ($STR) {
$result = $str;
return $result;
}

The first step is to generate the code
PHP provides a code generator-like tool Ext_skel for extended development convenience, see the Php.net official note (https://svn.php.net/repository/php/php-src/trunk/ Readme. Ext_skel).

Create a file, Tao.skel, whose contents are

String tao_string (String str)

is to tell Ext_skel this thing, we want to do the extension inside there is a function called tao_string. And then execute

The code is as follows Copy Code

CD mooenv/src/php-5.3.8/ext/
./ext_skel--extname=tao--proto=tao.skel
CD tao/

At this time, Tao, the extension of the code framework has come out.

Step two, modify the configuration
Then modify the config.m4 file to delete the first dnl of 10, 11, 123.

The code is as follows Copy Code

DNL Php_arg_with (TAO, for Tao Support,
DNL Make sure, the comment is aligned:
DNL [--with-tao Include Tao Support]

Revision changed to

Php_arg_with (TAO, for Tao Support,
Make sure, the comment is aligned:
[--with-tao Include Tao Support]

The third step is to realize the function
Modify Source TAO.C File
Find the Tao_string function modified to

The code is as follows Copy Code

Php_function (tao_string)
{
char *str = NULL;
int argc = Zend_num_args ();
int str_len;
Char *result;

if (Zend_parse_parameters (argc tsrmls_cc, "s", &str, &str_len) = = FAILURE)
Return

Str_len = spprintf (&result, 0, "Wo shi%.78s", str);
Return_stringl (result, str_len, 0);
}

Fourth step, compiling the extension
After saving, start compiling

The code is as follows Copy Code

/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make

Fifth step, add the extension
At this point, all goes well, the extension is already in the modules/tao.so position. The following is to add this extension to PHP, so that we can invoke the PHP program.

The code is as follows Copy Code

CP modules/tao.so/usr/local/php/ext/
Vim/usr/local/php/etc/php.ini
extension=/usr/local/php/ext/tao.so #在php. ini file last added this line
Service PHP-FPM Restart #重启PHP服务
CP tao.php/data/www/wwwroot/default/

Next you will be able to access the tao.php file and test the

http://www.bkjia.com/PHPjc/629901.html www.bkjia.com true http://www.bkjia.com/PHPjc/629901.html techarticle PHP Extension Development is not a thing that all developers will operate, below I will demonstrate a PHP extension development implementation process, you need to enter the reference. Let's first assume that we need ...

  • 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.