Home >Backend Development >PHP Problem >Is php extension development necessary?
There are two reasons why you need to write your own PHP extension. The first reason is: PHP needs to support a technology that it does not yet support. This usually involves wrapping some off-the-shelf C library to provide a PHP interface.
For example, if a database called FooBase has been launched on the market, you need to create a PHP extension to help you call FooBase's C function library from PHP. This work might be done by just one person and then shared by the entire PHP community (if you will).
The second reason, which is not very common, is that you need to write some business logic for performance or functionality reasons.
Download the php source code package: (Recommended learning: PHP video tutorial)
wget http://tw1. php.net/distributions/php-7.1.9.tar.gz
Unzip the source package. The Zend directory contains the Zend Engine source code for PHP. We need to briefly look at the definitions of some functions and macros here. one time.
The ext directory contains PHP native extensions, as well as tools that we can use when developing our own extensions. Use ext_skel under Linux and ext_skel_win32.php under Windows.
Use ./ext_skel - -help
./ext_skel --extname=module_name
You can generate your own extension in the ext directory
config.m4 configuration file
Develop PHP extension, in Before writing C code, you must configure this first. When we open it, we can see detailed annotation instructions, dnl is the annotation syntax.
If your extension uses external dependencies, configure the --with-hello option, otherwise configure the --enable-hello option and delete the del comments in the following 3 lines
PHP_ARG_ENABLE(hello, whether to enable hello support, Make sure that the comment is aligned: [ –enable-hello Enable hello support])
PHP_ARG_WITH and PHP_ARG_ENABLE Two macros are used to configure configure options, one configuration requires external dependencies, and the other configures configurations that do not require external dependencies.
The configured content can be seen when you execute configure –help later.
The above is the detailed content of Is php extension development necessary?. For more information, please follow other related articles on the PHP Chinese website!