Home >Backend Development >PHP Tutorial >A preliminary study on PHP C extension
Instructions
Environment:
<code> ubuntu14.4 php5.5.9 通过apt-get 安装 </code>
Because it is different from the compiled and installed php, you need to re-download the php source code for expansion.
<code>$ <span>sudo</span> apt-get <span>source</span> php5 </code>
The saving directory can be customized
Open the source code file and enter ext. This is where the extensions are stored. We can see that there are many official extensions
Here you can learn about the main directories and functions of PHP source code
./main contains PHP main macro definitions
./pear contains PEAR core files
./sapi contains different server abstraction layer codes
./Zend contains all files of the engine
We need to use the php-dev package, which will be built-in during compilation and installation. $sudo apt-get install php5-dev
$phpize-v
Verify whether the installation is successful
Officially start the expansion
Use ext_skel This file is in the ext directory $./ext_skel --extname=newext
This command is used in many tutorials, but I found during use that the newext.c file cannot be found in the subsequent process
Search for the operation just now and find that it will report cannot open /skeleton.c: No such file. It turns out that skeleton.c cannot be found. We can find it by looking at ext_skel
So you need to specify the path of skel
Delete the original newext directory and go through it again $ ./ext_skel --extname=newext --skel=/usr/lib/php5/skeleton
Return after success
According to the prompts, we need to change the comments of /newext2/config.m4
<code><span>$cd</span> newext2 <span>$phpize</span> $<span>.</span>/configure <span>--</span><span>with</span><span>-php</span><span>-config</span><span>=</span>/usr/bin/php<span>-config</span><span>$make</span></code>
It should be noted here that if there is a make irregular error, you need to check whether the php-config path is correct
If the compilation is successful, it will look like the following
<code><span>$make</span> test <span>$make</span> install</code>
Then we will modify the php.ini file
Add extension = newext2.so
Note that the php.ini files in cli mode and cgi mode are different. When I first started experimenting, I found that using
<code><span>$usr</span>/bin/php <span>-m</span></code>
in cli mode did not find the extension of newext2
Later, when I output phpinfo under cgi, I can see it
Later, I output phpinfo under cli, found the path to php.ini, made modifications and finally succeeded
If the phpinfo output in the console is too large, you can use the following method
<code><span>$ </span>php phpinfo.php | less </code>
Find the path and change it
Don’t forget to restart apache after modification
There are many related tutorials on the Internet. I referred to Chapter 7 of "PHP and New Technologies and Best Practices" and summarized the problems I encountered in actual operations, especially for non-compiled installation of PHP. In this case, the main thing is to pay attention to the path problem of the configuration file.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above has introduced a preliminary study on PHP C extension, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.