In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to customize the extension of PHP". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to customize the extension of PHP"!
Automatically generate extended directory structure by using source code tools
First go to the php source ext directory and execute the following command
/ www/test/php/php/bin/php ext_skel.php-- ext helloworldcd helloworld
Modify the config.m4 configuration file, that is, if the extension you are writing now uses external dependencies, configure the-- with-hello option, otherwise configure-- enable-hello option, and remove the comments according to your own needs.
Dnl If your extension references something external, use 'with': PHP_ARG_WITH ([helloworld], [for helloworld support], [AS_HELP_STRING ([--with-helloworld], [Include helloworld support])]) dnl Otherwise use' enable':
Extended function writing
Then vim helloworld.c writes the extended function code.
Let's take a look at the module structure definition first.
Zend_module_entry helloworld_module_entry = {STANDARD_MODULE_HEADER, "helloworld", / * Extension name * / helloworld_functions, / * zend_function_entry * / PHP_MINIT (helloworld) / * PHP_MINIT-Module initialization * / NULL, / * PHP_MSHUTDOWN-Module shutdown * / PHP_RINIT (helloworld), / * PHP_RINIT-Request initialization * / NULL / * PHP_RSHUTDOWN-Request shutdown * / PHP_MINFO (helloworld), / * PHP_MINFO-Module info * / PHP_HELLOWORLD_VERSION, / * Version * / PHP_MODULE_GLOBALS (pib), NULL, STANDARD_MODULE_PROPERTIES_EX}
Function name set
Static const zend_function_entry helloworld_functions [] = {PHP_FE (helloworld_test1, arginfo_helloworld_test1) PHP_FE (helloworld_test2, arginfo_helloworld_test2) PHP_FE_END}
Real function code
PHP_FUNCTION (helloworld_test2) {int argc = ZEND_NUM_ARGS (); char * messages = NULL; size_t messages_len = 0; char * context = NULL; size_t context_len = 0; zend_string * retval ZEND_PARSE_PARAMETERS_START (0,2) Z_PARAM_OPTIONAL Z_PARAM_STRING (messages, messages_len) Z_PARAM_STRING (context, context_len) ZEND_PARSE_PARAMETERS_END (); retval = strpprintf (0, "Hello% s test s", messages, context); RETURN_STR (retval);}
Function parameter definition
ZEND_BEGIN_ARG_INFO (arginfo_helloworld_test2, 0) ZEND_ARG_INFO (0, str) ZEND_END_ARG_INFO ()
Compilation and installation
/ www/test/php/php/bin/phpize./configure-- with-php-config=/www/test/php/php/bin/php-configmake & & make install
Now that you have the file helloworld.so in the extension directory of PHP, add the extended configuration to php.ini
Extension = helloworld.so
Then you can test the function you wrote, helloworld_test2 ()
At this point, I believe you have a deeper understanding of "PHP how to customize the extension", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.