Build a PHP extension development environment in Windows

Source: Internet
Author: User
Tags vc9
Build a PHP extension development environment in Windows. 1. prepare to download and install the PHP5.4.5 program for VS2008 in advance: Download TS from the ETS. The php binary packages include VC6, VC8, VC9, TS, and CTS. VC6, VC8, and VC9 correspond to VC6, VC2005, and VC2008TS respectively (ThreadSafe). when ISAPI (IISSERVER) permits, because PHP extension development environment is set up in a single Windows system

I. prepare in advance

Download and install VS2008

Download the PHP5.4.5 program:

NT download

TS download

The php binary packages include VC6, VC8, VC9, TS, and ETS.

VC6, VC8, and VC9 correspond to VC6, VC2005, and VC2008 respectively.

TS indicates (Thread Safe). when ISAPI (iis server) is allowed, we recommend that you use the TS version to avoid memory leakage and shared variable security because multiple threads are executed in a single process.

When executed with a single process such as FAST_CGI, the thread security check is not required.


Download PHP5.4.5 source code

Download PHP-SDK

Download MSYS, which includes the implementation of the linux compiler in Windows

Download deps


The following configuration basics are based on the f: \ php_stdio folder.


2. compile PHP

Download php-sdk first, download the newer php-sdk-binary-tools-20151115.zip, and decompress it

F: \ php_stdio \ php-sdk

Directory. Note: After decompression, the bin and script sub-directories should exist in this directory.

Open a cmd window, switch to the f: \ php_stdio \ php-sdk directory, and run vcvarsall. bat to set the compiling environment variable.

VS2008 installation path \ VC \ vcvarsall. bat

The specific directory of vcvarsall. bat depends on your installation location.

Next, go to the cmd window and continue to run the following command:

Bin \ phpsdk_setvars.bat

Bin \ phpsdk_buildtree.bat php54dev

In this way, an additional php54dev directory is added to the f: \ php_stdio \ php-sdk directory.

Decompress deps

F: \ php_stdio \ php-sdk \ php54dev \ vc9 \ x86 \

Directory. All subdirectories in the deps directory under this directory are empty. after decompression, copy them to many necessary library files for modules/extensions.

Next, copy the PHP-5.4.5 source code directory

F: \ php_stdio \ php-sdk \ php54dev \ vc9 \ x86 \

Directory. Go to the php source code directory

Cd f: \ php_stdio \ php-sdk \ php54dev \ vc9 \ x86 \ php-5.4.5.

Run

Buildconf

Then you can compile php first. At the very beginning, we usually compile as few modules as possible so that the core can be compiled properly:

Configure -- disable-all -- enable-cli


The main purpose of this step is to generate config. w32.h. if you need to generate PHP, you can continue to execute


Nmake clean; nmake

Php5.4 and a command line tool are compiled. Nmake clean is used to avoid interference caused by Legacy compilation intermediate result files.


3. create new extension my_fopen

The basic structure of PHP extension is the same. for the convenience of PHP Development, ext_skel and ext_skel_win32.php are extension skeleton building tools in linux and windows respectively.

This article describes how to build a PHP extension development environment in Windows, so ext_skel_win32.php is used. The new extension skeleton generated by it can be opened directly with.


Is a parameter supported by ext_skel_win32.php

Commonly used are -- extname and -- proto:

Extname: name of the extension

Proto: to facilitate the quick construction of the function skeleton, you can create a file and write the definition of each function.


cd f:\php_stdio\php-sdk\php54dev\vc9\x86\php-5.4.5\extphp ext_skel_win32.php --extname=my_fopen


The execution result is displayed, indicating that the new extension skeleton is successfully generated. now open f: \ php_stdio \ php-sdk \ php54dev \ vc9 \ x86 \ php-5.4.5 \ ext to see the my_fopen folder. Enter my_fopen to view my_fopen.dsp, which is the project file of.

Now you can develop the extension you want.



IV. Compile and use extensions

Currently, no function interfaces are created for the new extension, but the default extension provides us with a function interface for testing,

The default function naming rule is confirm _ [extname] _ compiled.

Function interface: tring confirm _ [extname] _ compiled (string)


1. use VS to open my_fopen.dsp

2. set project properties-configure properties-C/C ++-code generation and set the runtime library: multi-thread DLL (/MD)

3. set project properties-> configuration: Switch to Release_TS


4. set project properties-configure properties-C/C ++-advanced, set compilation to: compile to C code (/TC)

5. set project properties-configure properties-linker general, set the output file: Release_TS/php_my_fopen.dll.

If this parameter is not set, it will be difficult to find an extension after compilation and generation. Therefore, this setting is not required.

6. set project properties-configure properties-linker General, add additional Library Directory: F: \ php_work \ php-5.4.5 \ dev

If this option is not set, the following message is displayed during compilation: the input file "php5ts. lib" cannot be opened"


7. press F5 to execute the compilation. Will generate php_my_fopen.dll


1 success indicates that the dll is successfully generated.


Now that the extension has been compiled successfully, use it in PHP.

8. copy php_my_fopen.dll to F: \ php_work \ php-5.4.5 \ ext

8. open F: \ php_work \ php-5.4.5 \ php. ini and add extension = ext/php_my_fopen.dll

9. create F: \ php_work \ test. php

Echo confirm_my_fopen_compiled ("test ");


V. problems with compiling new extensions

1. fatal error C1902: The Program database manager does not match. check the installation
Mspdbsrv.exe or mspdbcore. dll is lost or their versions are different from those of mspdb80.dll. make sure the same versions of the three files are installed in the system.
Copy the three files in the \ Common7 \ IDE directory under the VC installation directory to the VC \ bin directory under the installation directory.

2 ../main/config. w32.h open failed
Config. w32.h is generated only after the PHP source code is configure.

3. the input file "php5ts. lib" cannot be opened"
Set C ++-> Advanced-> compile to C code (/TC) on the project property page, and choose linker-> Add the dev directory of the PHP binary package to the additional Library Directory.


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.