This article will introduce to you how to use VS2015 (vs14) to develop PHP7 extensions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Preparation work before development:
VS (I use 2013)
Cygwin (Download address: http://www. cygwin.com/)
Equipped with IIS7.5 of PHP running environment (used for testing)
php compiled program and pre-compiled source code, I am using the latest version 7.0. 5 (Download address: http://windows.php.net/download#php-7.0)
Compiled program path: E:\vs_c \test\phpext\php-7.0.5-src
Source code path before compilation: E:\vs_c \test\phpext\php-7.0.5-nts-Win32-VC14-x86\
Steps:
1. Install Cygwin
Install from the network
TEST=1 (The red part here needs to be changed to your extension name. If you don’t change it to your extension name, php will not recognize it)
TEST (Here The red part needs to be changed to your extension name. If you don’t change it to your extension name, PHP will not recognize it)
ZTS (Adding this variable turns on thread safety, not adding it turns off thread safety. You can judge whether to add this variable based on whether the php you compiled is thread safe. ps: I suffered a loss because of not responding. PHP does not recognize the extension)
Generate the solution. The error message shows that "config.w32.h" cannot be found. Search for "config.w32.h" in the source code file directory. h", find "config.w32.h.in" in the E:\vs_c \test\phpext\php-7.0.5-src\win32\build\ folder, and copy this file to E:\vs_c \test \phpext\php-7.0.5-src\main\ folder, remove the following ".in"
Generate the solution again, and the error message LNK1120
error 7 error LNK1120: 5 unresolved external commands E:\vs_c \test\phpext\php-7.0.5-src\ext\test\Release\phptest.dll 1 1 phptest
right-click project properties, connector, enter , additional dependencies, edit, put the path to php5.lib (this file is in the program folder after php is compiled, in the dev folder of the root directory)
Note: In order to allow the extension to work with php The running environment matching depends on the compiled version of your php running environment (php7.0.5 is compiled by VC14), which is the config in the E:\vs_c\test\phpext\php-7.0.5-src\main\ folder. Add to the w32.h file:
#define PHP_COMPILER_ID "VC14"
Open E:\vs_c \test\phpext\php-7.0.5-src\ext\test\test.c
Find this paragraph Code:
PHP_FUNCTION(confirm_test_compiled) { char *arg = NULL; int arg_len, len; char *strg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "test", arg); RETURN_STRINGL(strg, len, 0); }
Change confirm_test_compiled to test_echo
Find this code again:
const zend_function_entry test_functions[] = { PHP_FE(confirm_test_compiled, NULL) /* For testing, remove later. */ PHP_FE_END /* Must be the last line in test_functions[] */ };
Change confirm_test_compiled inside to test_echo
To generate a solution, find your own php extension phptest.dll in the Release folder of the project root directory, copy it to the ext folder of php, and configure it in php.ini:
extension=phptest.dll
Restart IIS, create a new site, and create a new test.php file in it
<?php echo test_echo("123");
Run and get the result:
The above is the detailed content of How to develop PHP7 extensions with VS2015 (vs14). For more information, please follow other related articles on the PHP Chinese website!