[Php extension and embedded]-install and build the environment

Source: Internet
Author: User
Tags zts automake

To install the Build Environment, you may already have at least one installed php and have used it for web-based application development. you may have downloaded win32 from php.net and run it on iis or windows apache, or use your * nix (linux, bsd, or other POSIX-compliant releases) the package management system of the release version installs binary files created by a third party. build php unless you download the source code package and compile it yourself, you will miss some knowledge points. * The first required tool in the nix tool C developer tool set is the C compiler. your release may include one by default. If Lucky, it is the gcc (GNU Compiler set ). you can run gcc version or cc version to check whether the compiler is installed. If yes, it will respond to the installed version information. if you have not installed the compiler, you can download and install gcc as specified by the official release. this usually means to download. rpm or. deb file and execute a command Install it. this depends on the release version you are using. You can use the following command to install urpmi gcc, apt-get install gcc, pkg-add-r gcc, and emerge gcc. in addition to the compiler, you also need the following programs and tools: make, autoconf, automake, and libtool. these tools can also be installed using the package management system of the release version you are using, just like installing gcc, or directly download the source package from gnu.org and compile it yourself. recommended versions: libtool 1.4.3, autoconf 2.13, automake 1.4 or 1.5. the updated versions of these software may also work well, but these versions have been verified for a long time. if you plan to use CVS to check out the latest php development code, you also need bison and flex to construct the language interpreter. like other packages, these two packages can be installed using your release package management system, or under gnu.org Compile the source code. if you select CVS, you also need to install the cvs client. similarly, it may have been installed on your release, or you can download and compile it yourself. unlike other packages, You need to download this package at cvshome.org. the Win32 tool translator is not familiar with the windows environment and therefore skipped. when you download php source code, you have a centralized selection. first, if your release supports, you can use commands such as apt-get source php5 to download. this method is a bit because the release you are using may have some problems and you need to modify the php source code. download it from here, it is certain that these problems have been patched to make your build have fewer problems. the disadvantage is that most releases will be several weeks behind official php releases. another option is to download php-x.y.z.tar.gz (x. y. z is the current version ). these php releases have been tested by countless php users around the world and are the latest. you can also S.php.net downloads the Snapshot package. on this site, the latest version of all source code in the php version library will be packed every several hours. some submission by php kernel developers may temporarily make it unavailable. However, if you need the latest php 6.0 features before the official release, this is the easiest way to get it. finally, you can use cvs to directly obtain the development version used by the php kernel development team. if you only want to develop extensions and embedded programs, there is no obvious benefit compared to using official release packages and getting snapshots. however, if you plan to release your extension or other applications to the CVS library, it is useful to be familiar with the check-out process. php currently uses git to manage the code library. For details about cvs check-out, visit https://github.com/php/php-srcto obtain the latest source code. if you want to contribute code to php, you can view the home page of the project. we have discussed the configuration of php for development in Chapter 1. Whether you plan to develop extensions or dive into other php applications, there are two ways to build developer-friendly php: Special. you need to use the/configure switch. These two switches should be used together with other switches used when you build php. enable-debug enables debugging on some key functions in the php and zend source code trees. first, it enables the Memory Leak report after each request ends. looking back at Chapter 3 "Memory Management", ZendMM implicitly releases the memory allocated for each request, but is not released before the script ends. by running a series of regression test cases on the newly developed code, leakage points can be easily exposed, so that they can be repaired between releases. let's take a look at the following code snippet: [cpp] void show_value (int n) {char * message = emalloc (1024); sprintf (message, "The value of n is % d \ n", n); php_printf ("% s", message);} if this stupid code is executed during php request execution, it will leak 1024 characters Memory. generally, ZendMM will release the script after it is executed. when enable-debug is enabled, the developer will receive an error message: [cpp]/cvs/php5/ext/sample. c (33): Freeing 0x083694b8 (1024 bytes ), script =-= Total 1 memory leaks detected = This short but complete message tells you that ZendMM is cleaned up after you dirty the memory, it also shows where the leaked memory block is allocated. with this information, it is easy to locate the problem, open the file, find the corresponding row, and add efree (message) at the appropriate position before the function ends ). of course, memory leakage is not the only hard-to-trace problem you will encounter. sometimes, problems are potential and seldom appear. for example, you have modified a lot of code and source files by working all night long. After everything is done, you are confident to execute make and Test A simple script, then we can see the following output: [cpp] $ sapi/cli/php-r 'myext _ samplefunc (); 'Segmentation Fault, which is just a representation, where is the problem? Check your myext_samplefunc () implementation. There is no obvious clue. Running gdb only shows a string of unknown symbols. similarly, enable-debug will help you. in. /Add this toggle when configure, And the php binary result will contain all the debugging symbols required by gdb and other core file check programs. This will show where the problem is. use this option to re-build and trigger the crash through gdb. Now you can see the following output: [cpp] #0 0x1234567 php_myext_find_delimiter (str = 0x1234567 "foo @ # (FHVN) @ \ x98 \ xE0... ", strlen = 3, tsrm_ls = 0x1234567) p = strchr (str, ','); the target is clear. the str string is not terminated by NULL. The following garbage can prove this, rather than the binary safe function uses it. strchr () is used to scan the input str from start to end. However, since the NULL byte is not terminated, it reaches the memory that does not belong to it, which leads to a segment error. we can use memchr () and strlen parameters to fix this problem and prevent crash. enable-mantainer-zts this option forces php to build and enable the thread security resource management (TSRM)/Zend thread security (ZTS) layer. this switch will increase the processing complexity, but for developers, you will find this is a good thing. for more information about ZTS and how to enable this option during development, see Chapter 1. enable-embed if you want to develop another application embedded in php, you need another very important switch. after this switch is turned on, a dynamic link library (mod_php5.so) similar to the dynamic link library (libphp5.so) built after with-apxs is turned on will be built. It can be used to embed php into other applications. compile on Unix now you have all the tools you need, download the php source code package, and get to know all the required tools. the/configure switch is a real compilation PHP. Here, you can download php-5.1.0.tar.gz in your home directory. You will use the following command sequence to unpack the source code package and switch to the decompressed source code directory: [cpp] [/home/sarag] $ tar-zxf php-5.1.0.tar.gz [/home/sarag] $ cd php-5.1.0 if you are not using gnu tar, the command may need to be slightly modified: [cpp] [/home/sarag] $ gzip-d php-5.1.0.tar.gz | tar-xf-now, run with the required switch and other options you want to enable or disable. /configure commands: [cpp] [/home/sarag/php-5.1.0] $. /configure enable-debug \ enable-maintainer-zts disable-cgi enable-cli \ disable-pear disable-xml disable-sqlite \ without-mysql enable-embed after processing for a period of time, A lot of information is output on your screen, and the process is complete. /configure stage. next you can start compiling: [cpp] [/home/sarag] $ make all install now, stand up and have a cup of coffee. it may take several minutes to compile on a machine with high performance, or even half an hour on the old 486. after the build process is complete, you have a correct configuration, complete functions, and can be used to develop php.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.