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