Windows stops making PHP extensions

Source: Internet
Author: User
Tags apache error log php server
Making PHP Extensions under Windows

Making PHP Extensions under Windows
January 26, 2011
Turn from: ml
Some of the required headers for compiling PHP extensions need to be obtained from the PHP source, and some of the configuration header files need to be done after the 8th step below, that is to say, the PHP server program can use the installation package that someone else has compiled. Recently in the learning to write PHP extension, lazy to install Linux, the study of the method of compiling PHP under Windows, finally set up in Windows under the development of PHP expansion environment.
1. Create a new folder in the C drive, C:\PHPDEV
2, download the latest version from the official website (I use the 5.2.14) PHP source, the next tar.gz or tar.bz2 compressed package to save to C:\PHPDEV, extract to the current folder
3, download PHP Win32 build Extras and save to C:\PHPDEV, unzip to the current folder
4, get compiled Bison.exe and Flex.exe, save to the desktop or other places outside the C:\PHPDEV. Open the package separately and go to the Bin folder to copy Bison.exe and Flex.exe to the C:\Windows folder
5. Assume that you have installed Visual Studio 2008 (I personally do not recommend using Visual Studio 2008, it is recommended to use the platform SDK Febrary 2003, the official compiled version is compiled with this psdk, but here with the visual Studio 2008 for instructions), Start menu->microsoft Visual Studio 2008->visual Studio tools->visual Studio Command Prompt, Open the Visual Studio 2008 Command Prompt Line
6. Switch directories to C:\PHPDEV\php-5.2.14 with the CD command
7. Input Buildconf.bat, enter. The role of this batch is to search all the. w32 files and create a configure.js for you
8. Enter the following command
Cscript/nologo configure.js without-xml without-wddx without-simplexml without-dom without-libxml disable-zlib- Without-sqlite disable-odbc disable-cgi enable-cli enable-debug without-iconv Disable-ipv6
Why should disable and without so versatile? Because the library files required for these features are not included in the PHP source bundle (otherwise very large), these additional library files need to be downloaded yourself (not so easy to find). If you can't help using these features, a compilation error will occur.
9. Input NMAKE, enter
10, the 9th step may appear the file encoding error, found the error file, with EditPlus select Western European (Windows) encoding opened Save as utf-8 encoding, rewrite NMAKE can
11. After compiling, switch to C:\PHPDEV\php-5.2.6\Debug_TS and test it.
Php-r "Echo ' Hello,world ';" ii. developing PHP extensions under Windows
Turn from: 909.aspx
First step: Prepare
1. PHP Source package and binary package under Windows, and install Visual C + +, and add the absolute path of Microsoft Visual Studio\common\msdev98\bin to the Windows environment variables
2, unzip the source package to D:\PHP_SRC
3, enter the D:\php_src\ext directory, copy the skeleton folder, and rename the name to develop the extension, this example is "Linvo"
4. Copy the Php5ts.lib file from the dev directory in the binary package into the new Linvo directory
5, edit the Linvo directory Php_skeleton.h, SKELETON.C, skeleton.dsp These three files, the replacement content of all Extname is linvo,extname for Linvo. (Strictly case-sensitive)
Step Two: Encode
6. Edit the Php_skeleton.h file (header file)
In Php_function (confirm_linvo_compiled);
Php_function (hello);
Declaring a Hello function
7. Edit the Skeleton.c file (main file)
Written under Php_fe (confirm_linvo_compiled, NULL)
Php_fe (Hello, NULL)
This is the function entry, the following is the writing function body
Locate the Php_function (confirm_test_compiled) function, which is a test function that writes a new function after the function
Php_function (Hello)
char *arg = NULL;
int Arg_len, Len;
Char *STRG;
/* Receive parameters */
if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &arg, &arg_len) = = FAILURE) {
Len = spprintf (&STRG, 0, "hello,%s", Arg);
Return_stringl (STRG, Len, 0);
Step three: Compiling
8. Run the cmd command line and enter the D:\php_src\ext\linvo directory
9, input Msdev linvo.dsp/make "Linvo-win32 release_ts"
10, if there is no error, the PHP_SRC directory will generate a Release_ts folder, which is the compiled Php_linvo.dll extension
Fourth Step: Use
11, copy it into the operating environment of the PHP extension directory ext
12, edit php.ini add Extension=php_linvo.dll, restart Apache
13. Execute the following statement in the PHP file
echo Hello (' linvo ');
The output
14, through the Echo phpinfo (); You can also see the information that the extension has loaded
LINVO Support Enabled third, loading problems
When the generated extension is put into a folder, and after modifying the php.ini, it is possible that the generated extension DLL is not loaded by PHP and can be checked in the following ways.
1, create a PHP, and use the Phpinfo () function to play the current PHP information, to find the real load in PHP php.ini.
2. Have you restarted Apache?
3. Check the Apache error log to see if there is any information about loading the extension error. If it appears "PHP warning:php Startup:extname:Unable to initialize Module\nmodule compiled with module api=20090626, debug=0, th Read-safety=1\nphp compiled with module api=20060613, debug=0, Thread-safety=1\nthese options need to match\n in Unknown o N Line 0 "Note that the compile-time use of the source version of the PHP application does not conform (does not require a fully consistent version), if there is a non-conformance.
4, write the extension whether reference other DLLs, for this kind of problem reason, see:
  • Related Article

    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: 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.