This article mainly introduces the compilation of phpredis in the window (linux compilation is very simple, direct co source code, direct make, it is not worth mentioning, well)
This article mainly introduces the compilation of phpredis in the window (linux compilation is very simple, direct co source code, direct make, it is not worth mentioning, well)
Project Source: https://github.com/nicolasff/phpredis
Compilation tool: vs2010
Compiled version: php5.4. * (PHP_API_VERSION: 20100412) + phpredis2.2.1
Preparations before compilation:
Download php source code: http://www.php.net/downloads.php
Download php5ts. lib: http://windows.php.net/download/#php-5.4 (download the corresponding version of the zip file, php5ts. lib in the compressed file dev directory)
Download cygwin: http://cygwin.com/install.html
The win32 compilation tool in the PHP site is http://www.php.net/extra/win32build.zip.
Source code of the DNS parser used by PHP: http://www.php.net/extra/bindlib_w32.zip. Replace resolv. lib in win32build.zip with this.
Download igbinary: https://github.com/remicollet/igbinary
Directory structure
+ -- Php
| + -- Php-5.4 .*
| + -- Ext
| + -- Phpredis
| + -- Igbinary
| + --...
| + --...
| + -- Win32build
| + -- Bindlib_w32
Compilation steps:
1. install cygwin
II. generate a php compiling environment
Execute buildconf. bat in the php-5.4. * Directory
Execute configure. bat in the php-5.4. * Directory
Copy php5ts. lib to the php-5.4. * Directory
3. use cygwin to generate the phpredis project file
Modify $ cygwin_path (19 rows) in the php-5.4. */ext/ext_skel_win32.php file to be correctly configured
Execute php ext_skel_win32.php -- extname = phpredis in the php-5.4. */ext Directory (note that if php environment variables are not configured, php needs to write the full path)
Copy the downloaded phpredis project source code to the php-5.4. */ext/phpredis Directory
Copy the downloaded igbinary to the project source code php-5.4. */ext/phpredis/igbinary Directory
4. use vs2010 to import the phpredis project
Open the redis. dsp project file in the php5.4. */ext/phpredis directory and open the project
Add php-5.4. */ext/phpredis/all. h and. c file to the project (right-click "redis" project in Solution Explorer> Add> existing item, shortcut key shift + alt +)
In solution explorer, right-click "redis" project-> Select "properties" to open the "redis properties Page"
On the "redis properties page" page, select "configuration properties"-> c/c ++-> pre-processor, and select "pre-processor definition" on the right interface ", open the pre-processor management interface, delete PHP_EXPORTS, ZEND_EXPORTS, and LIBZEND_EXPORTS, and add HAVE_REDIS_IGBINARY. For example:
On the "redis properties page" page, choose "configuration properties"> "linker"> "input" and select "Add dependency" on the right to open the "add dependency" management interface, add php5ts to the input box. lib and ws2_32.lib. For example:
Now the phpredis project configuration is complete, and the next step is to compile
5. Compile the project
At this time, in theory, you can click compile directly and then smoothly compile the program. However, if it is a smooth compilation process, I do not need to write this article nonsense, because php extension compilation has already been written by many experts, and it is much more detailed than this article.
6. modify the phpredis project file
Delete the php api in the project file. Note that this deletion can ensure that the project can be compiled and used in actual development, but I don't know what this means. You are welcome to Gao renpai.
During compilation, "error c2275: *** using this type as an invalid expression" is reported. this error is reported because these statements are based on the c99 standard, while vs2010 does not support the c99 standard. Therefore, you need to find the corresponding row and put the variable declaration and adjustment at the beginning of the function.
In the redis. c file, find the atoll (val_str) function and change it to atol (val_str) (atoll is c99 standard, not supported by vc2010 ).
Modify the vc/include/sys/stat. inl, vc/include/malloc. h files under the vs installation target
# Ifndef _ STATIC_ASSERT
# Define _ STATIC_ASSERT (expr) typedef char _ static_assert_t [(expr)]
# Endif
Change
# Ifndef _ STATIC_ASSERT
# Ifdef PHP_WIN32
# Define _ STATIC_ASSERT (expr) typedef char _ static_assert_t [(expr )? (Expr): 1]
# Else
# Define _ STATIC_ASSERT (expr) typedef char _ static_assert_t [(expr)]
# Endif
# Endif
Common errors and solutions during project compilation:
"Error LNK2001: the external symbol _ basic_globals_id that cannot be parsed". The problem is that the 3rd small step in step 4 is not correctly executed.
"LINK: fatal error LNK1181: the input file php5ts. lib cannot be opened." The problem is that php5ts. lib is not copied to the correct directory.
"Error LNK2019: an external symbol that cannot be parsed _ imp _ setsockopt @ 20, which is referenced in function _ redis_sock_connect." The problem is that ws2_32.lib is not added to step 4.
"Error C2491:" redis_stream_close ": the dllimport function definition is not allowed." delete the PHPAPI before the corresponding row.