Home >Backend Development >PHP Tutorial >Develop php extensions under Window7, develop php extensions under window7_PHP tutorial
1. First check the phpinfo() information
PHP Version 5.4.34
Zend Extension Build API220100525,TS,VC9
PHP Extension Build API20100525,TS,VC9
Thread Safety enable
Thread safety, VC9 compilation, version 5.4.34
2. Preparation work before development
php 5.3-5.4: Visual C 9.0 (Visual Studio 2008)
Install Cygwin (download address: http://www.cygwin.com/), virtual linux environment
PHP compiled program and pre-compiled source code (download address: http://windows.php.net/download/ )
Compiled program path: php-5.4.45-Win32-VC9-x86
Pre-compiled source code path: php-5.4.45-src
Download the php sdk file, http://windows .php.net/downloads/php-sdk/
1. Unzip the files in php-sdk-binary-tools-20110915.zip and add the bin directory where bison.exe is located to the system path
Copy php-5.4.45-Win32-VC9-x86devphp5ts.lib to php-5.4.45-srcRelease_TSphp5ts.lib
Create a new php-5.4.45-srcmainconfig.win32.h with the following content:
#define SIZEOF_LONG 4
#define PHP_COMPILER_ID "VC9"
"VC9" corresponds to VC9
2. Find the php source code directory, php-5.4.45-srcextext_skel_win32.php
<span> 1</span> <span>/*</span> <span> 2</span> <span> This script can be used on Win32 systems </span><span> 3</span> <span> 4</span> <span> 1) Make sure you have CygWin installed </span><span> 5</span> <span> 2) Adjust the $cygwin_path to match your installation </span><span> 6</span> <span> 3) Change the environment cariable PATHEXT to include .PHP </span><span> 7</span> <span> 4) run ext_skel --extname=... </span><span> 8</span> <span> the first time you run this script you will be asked to </span><span> 9</span> <span> associate it with a program. chooses the CLI version of php. </span><span>10</span> <span>*/</span> <span>11</span> <span>$cygwin_path</span> = 'D:\Program Files\cygwin\bin';
Change this to your cygwin installation directory.
3. Run cmd, enter the php source code directory, php-5.4.45-srcext, and run the command php ext_skel_win32.php --extname=myphpexs
Remember to add the directory where php.exe is located to path, --extname=your extension name.
If successful, the myphpexs folder will be generated in the ext directory with the following content
4. Open myphpexs.dsp with vs2008, change the solution configuration to Release, and execute the generation command
If it goes well, the php_myphpexs.dll file will be generated. Mine will generate php_myphpexs.dll and then the Release_TS file in the php source code root directory. folder
5. Place php_myphpexs.dll in your php extension directory, and add extension=php_myphpexs.dll to php.ini
6. Create a new php script file test.php, The content is as follows
<span>1</span> <span>echo</span> confirm_myphpexs_compiled('test');
7. Run the test file and the following content will appear. It is successful.
Congratulations! You have successfully modified ext/myphpext/config.m4. Module 23 is now compiled into PHP.
8. confirm_myphpexs_compiled The extension is created with its own volume function. When editing your own extension content, you can delete and modify the function