Ipvmsys (MSYS is similar to Cygwin, but because of its different operating principles, it is faster, smaller in size, powerful, and easy to build php extensions with VC
The source file and installation package of software php must be consistent
Php5.3.8 (VC9 x86 Thread Safe)
Php5.3.8source file (tar.bz2)
VC
Bison.exe
MSYS (MSYS is similar to Cygwin, but due to different working principles, faster, smaller, powerful, easy to carry http://code.google.com/p/msys-cn)
Because my development is just a very simple demo, no third-party class libraries are used. Some libraries may be used for extension projects taken from linux. It may be better to use cygwin. But no cygwin can be developed in Windows.
1. Decompress the downloaded source file tar.bz2 to drive c:/phpsrc, and decompress the php installation package (VC9 x86Thread Safe, that is, the php compressed package file that can be used normally) to C:/php, we only need a file C:/php/dev/php5.lib in it to copy php5.lib to c:/phpsrc.
2. Copy bison.exe to Microsoft Visual Studio \ Common \ MSDev98 \ Bin and add the absolute path of Microsoft Visual Studio \ Common \ MSDev98 \ Bin to the windows environment variable.
3. Here we start generating config. w32.h. CMD operation in it
Enter: c:/phpsrc to execute
C:\phpsrc>buildconfRebuilding configure.jsNow run 'configure --help'
? Create a temporary environment variable
C:\phpsrc>set path=%path%;C:/phpsrc/binC:\phpsrc>cscript /nologo configure.js --with-php-build="../phpsrc" --without-libxml --disable-odbc
If you want the Non-Thread Safe mode, remove the last parameter -- disable-zts
Saving configure options to config. nice. batChecking for cl.exe...
Detected compiler MSVC9 (Visual C ++ 2008) Detected 32-bit compilerChecking for link.exe... C: \ Program Files \ Microsoft Visual Studio 9.0 \ VC \ BINChecking for nmake.exe...
Checking for lib.exe...
........... Omitted in the middle ............. --------------------------------------- | builds | Build type | Release | Thread Safety | Yes | Compiler | MSVC6 (Visual C ++ 6.0) | Architecture | x86 | --------------------------------------------- Type 'nmake' to build PHP
If a similar prompt appears, it means that your PHP development environment has been set up successfully, and a config. w32.h is added under main. That is, the configuration file of the PHP development environment. Without this script, it would be miserable to develop php in windows.
?
4. develop PHP extension methods
Here we can build and develop PHP extensions, but we can't help but what should we do? in fact, PHP also provides us with a very useful tool to build a PHP extension skeleton. It is how to run ext_skel_win32.php under C: \ phpsrc \ ext. it ends with php and it depends on php. The following describes how to create an extension named 'test. In this case, make sure that your php.exe can be used directly under cmd, and add the Path to it. Although ext_skel_win32.php ext_skel_php is executed in php, we do not know the specific content. Execute the following command:
C: \ phpsrc \ ext> php ext_skel_win32.php 'sh' is not an internal or external command, or a runable program or batch file.
In the source code of ext_skel_win32.php, cygwin is used, but cygwin is not installed on my machine. In addition, I found that only sh is used, and sh is also used in the MSYS installed on my machine, it should be usable, so the $ cygwin_path variable in ext_skel_win32.php is set to the BIN directory of MSYS.
$cygwin_path = 'c:\msys\1.0\bin';
?
C:\phpsrc\ext>php ext_skel_win32.phpext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]] [--skel=dir] [--full-xml] [--no-help] --extname=module module is the name of your extension --proto=file file contains prototypes of functions to create --stubs=file generate only function stubs in file --xml generate xml documentation to be added to phpdoc-cvs --skel=dir path to the skeleton directory --full-xml generate xml documentation for a self-contained extension (not yet implemented) --no-help don't try to be nice and create comments in the code and helper functions to test if the module compiledPHP Warning: fopen(/.php): failed to open stream: No such file or directory inC:\phpsrc\ext\ext_skel_win32.php on line 52C:\phpsrc\ext>
? You can see how to use this php script. The general command is as follows:
c:\phpsrc\ext>php ext_skel_win32.php --extname=testCreating directory testCreating basic files: config.m4 config.w32 .svnignore test.c php_test.h CREDITS EXPERIMENTAL tests/001.phpt test.php [done].To use your new extension, you will have to execute the following steps:1. $ cd ..2. $ vi ext/test/config.m43. $ ./buildconf4. $ ./configure --[with|enable]-test5. $ make6. $ ./php -f ext/test/test.php7. $ vi ext/test/test.c8. $ makeRepeat steps 3-6 until you are satisfied with ext/test/config.m4 andstep 6 confirms that your module is compiled into PHP. Then, start writingcode and repeat the last two steps as often as necessary.c:\phpsrc\ext>
In this way, a php extension skeleton is successfully created, which you can modify. You must study the php api carefully. The specific extension location is under the ext Directory. you can view the test folder, which was created by the command just now.
C: \ phpsrc \ ext \ test Directory
.
... Svnignore2011-11-29 1,970 config. m42011-11-29 282 config. w322011-11-29 16:57 4 CREDITS2011-11-29 16:57 0 EXPERIMENTAL2011-11-29 16:57 2,768 php_test.h2011-11-29 16:57 5,128 test. c2011-11-29 4,954 test. dsp2011-11-29 500 test. php2011-11-29 16: 57
Tests 9 files 15,622 bytes 3 directories 7,441,883,136 available bytes C: \ phpsrc \ ext \ test>
Such a php extension framework has been created.
?
The following is the configuration to use vc ++ 6 to develop this extension.
III. add the dependent php5ts. lib
? Copy php5ts. lib to the test directory under the dev directory of the php binary package. Otherwise, the compilation will fail.
IV. Add test c code
Key files in the generated test directory include
? Test. dsp,
? Test. c,
? Php_test.h,
Do not worry about other files.
Tip: Do not remove the ext directory from the test Directory. otherwise, php. h is missing.
1. modify php_test.h
New extended function: add a row after PHP_FUNCTION (confirm_test_compiled );
PHP_FUNCTION (confirm_test_compiled); PHP_FUNCTION (test); // New row
2. modify test. c.
Add our new function after PHP_FUNCTION (confirm_test_compiled)
PHP_FUNCTION(test){ php_printf("Hello C extension");}
Add a row to the array zend_function_entry test_functions [].
Const zend_function_entry test_functions [] = {PHP_FE (confirm_test_compiled, NULL)/* For testing, remove later. */PHP_FE (test, NULL) // the new row PHP_FE_END/* Must be the last line in test_functions [] */};
?V. build a DLL file
Open our project with vc6, which is test. dsp.
1. modify the compilation method to release: Select Build-> Set Active Configuration to Set the default compilation method to Release. Otherwise, the system will prompt the lack of php5ts_debug.lib, which is actually php5ts. lib.
2. press F5 to compile. Php_test.dll will be generated under the Release_TS directory at the ext level.
Tip: If you are willing to use the command line for compilation, the command is as follows:
msdev test\test.dsp /MAKE "test - Win32 Release_TS"
?VI. integrate dll into php.
?