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>
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>
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>
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>
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>
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/