In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to write a PHP extension under Linux". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to write a PHP extension under Linux" together!
hypothetical demand
Develop an extension called helloWord.
There is a function called helloWord().
echo helloWord ('Tom ');//returns: Hello World: Tom
local environment
PHP version: 5.6.9
Linux CentOS release 6.5 (Final)
final effect
realization flow
Step 1:
Go to the local php directory and execute: cd /root/soft/src/php-5.6.9cd ext./ ext_skel --extname=helloWordcd helloWordvi config.m4 Search: dnl Otherwise use enable Modify the following to: PHP_ARG_ENABLE(helloWorld, whether to enable helloWorld support,[ --enable-helloWorld Enable helloWorld support])if test "$PHP_HELLOWORLD" != "no"; then...
As shown in the figure:
Step 2:
vi php_helloWorld.h Search: extern zend_module_entry Add a new line: PHP_FUNCTION(helloWorld);
As shown in the figure:
Step 3:
vi helloWorld.c Search: const zend_function_entry helloWorld_functions[] Add a new line: PHP_FE(helloWorld, NULL)
As shown in the figure:
Add a method PHP_FUNCTION(helloWorld){ char *arg = NULL; int arg_len, len; char *strg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = spprintf(&strg, 0, "Hello World: %s", arg); RETURN_STRINGL(strg, len, 0);}
As shown in the figure:
Step 4:
//compile install cd /root/soft/src/php-5.6.9/ext/usr/local/php/bin/phpize #generate configure configuration file with phpize./ configure --with-php-config=/usr/local/php/bin/php-config #configure make #compile make install #install
Step 5:
//modify php.iniextension="helloWorld.so" #Name is the name of the installation extension
Step 6:
Restart the environment.
After completing the above steps, the simple helloWorld extension is OK.
Thank you for reading, the above is "how to write a PHP extension under Linux" content, after the study of this article, I believe we have a deeper understanding of how to write a PHP extension under Linux, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.