Php_redis.dll extends the entire compilation process (various pitfalls)

Source: Internet
Author: User
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:

  1. Download php source code: http://www.php.net/downloads.php

  2. 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)

  3. Download cygwin: http://cygwin.com/install.html

  4. The win32 compilation tool in the PHP site is http://www.php.net/extra/win32build.zip.

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

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

  1. Execute buildconf. bat in the php-5.4. * Directory

  2. Execute configure. bat in the php-5.4. * Directory

  3. Copy php5ts. lib to the php-5.4. * Directory

3. use cygwin to generate the phpredis project file

  1. Modify $ cygwin_path (19 rows) in the php-5.4. */ext/ext_skel_win32.php file to be correctly configured

  2. 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)

  3. Copy the downloaded phpredis project source code to the php-5.4. */ext/phpredis Directory

  4. Copy the downloaded igbinary to the project source code php-5.4. */ext/phpredis/igbinary Directory

4. use vs2010 to import the phpredis project

  1. Open the redis. dsp project file in the php5.4. */ext/phpredis directory and open the project

  2. 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 +)

  3. In solution explorer, right-click "redis" project-> Select "properties" to open the "redis properties Page"

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


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

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

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

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

  3. 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 ).

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

  1. "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.

  2. "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.

  3. "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.

  4. "Error C2491:" redis_stream_close ": the dllimport function definition is not allowed." delete the PHPAPI before the corresponding row.

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