Introduction to PHP extension development, introduction to php extension_PHP tutorial

WBOY
Release: 2016-07-12 08:56:56
Original
941 people have browsed it

Introduction to PHP extension development, introduction to php extension

Original text:http://www.orlion.ga/ 1090/

Write the simplest function to convert all strings into uppercase letters:

<span><?php
    function my_toupper($str) {
        return strtoupper($str);
    }
    
    echo my_toupper('demo');
?></span>
Copy after login

Now we develop a php extension to implement the function of my_toupper.

Step1:

PHP provides an extension framework generator: ext_skel. This tool is in the ext directory of the PHP source code (mine is /usr/local/src/php-5.6.17/ext/). First, we create an orlion.skel file in the ext directory of the PHP source code. The file content is:

<span>string my_toupper(string str)</span>
Copy after login

This file is to tell ext_skel that our extension has the my_toupper function, and then execute:

<span>./ext_skel --extname=orlion --proto=orlion.skel</span>
Copy after login

 

This step will create a folder orlion in the current directory. The directory structure is like this:

 

At this time, the extended framework is set up.

Step2:

Modify config.m4 in the orlion directory and remove the dnl in lines 10, 11, and 12 of this file:

means

 

changed to:

 

 

Step3:

The next step is to implement our function. Open orlion.c, then find the function PHP_FUNCTION (my_toupper) and modify it as follows:

 

Then compile the extension and run it in sequence:

<span>$ /usr/local/php/bin/phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make</span>
Copy after login

Step4:

To add the extension to php, first copy orlion/mudules/orlion.so in our extension to the php extension directory:

 

Then modify the configuration php.ini and add "extension=orlion.so" at the end of the file and restart php-fpm.

Step5:

Write a test.php file to test:

<span><?php
    var_dump(my_toupper('abc'));
?></span>
Copy after login

Run it and you will see the output of ABC, success!

For information on PHP kernel technology, please visit: http://www.orlion.ga/tag/php-internal/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1110528.htmlTechArticleGetting started with PHP extension development, getting started with php extensions Original text: http://www.orlion.ga/1090/ Write a The simplest function to turn all strings into uppercase letters: ?phpfunctionmy_toupper($str){returnstrtoupp...
Related labels:
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