Create and use php extension components under windows

development environment

1.win 7 32-bit
2.Visual Studio 2019 (desktop development components using C++ installed)

Preparation

1.php-sdk-binary-tools(v2.1.9)
2.php源码(v8.0.17)
3.php x86 Non Thread Safe (v8.0.17)

Make components

1. Generate component source code

cd php-8.0.17-src/ext // 进入php源码的ext目录
php ext_skel.php --ext myext // 生成组件源码

2. Open the compilation environment

cd php-sdk2.1.9  // 打开生成组件工具
phpsdk-vc15-x86.bat // 运行工具

3. Generate components

buildconf
configure --disable-all --enable-cli --enable-myext=shared --disable-zts
nmake

There are two points that need to be explained here, one is –enable-myext=shared, the reason why shared is to generate a separate, shareable dll file, and one is –disable-zts is a dll component that generates non-safe threads.

So far, the php_myext.dll component has been generated. Under php-8.0.17-src\Release, if –disable-zts is not added, it will be under Release_TS.

test component

1. Open php-8.0.17-nts-Win32-vs16-x86
2. Copy php_myext.dll to the ext directory
3. Modify php.ini-production to php.ini, and modify the following options

extension_dir = "ext"
extension=myext

4. Create a new test file test.php

$myext = extension_loaded('myext');
var_dump($myext);
test1();
$res = test2();
var_dump($res);

5. Whether the test is successful

./php test.php

The above directories are all based on php-8.0.17-nts-Win32-vs16-x86.

Precautions

1. Different PHP versions correspond to different Visual Studios.
Visual C++ 14.0 (Visual Studio 2015) for PHP 7.0 or PHP 7.1.
Visual C++ 15.0 (Visual Studio 2017) for PHP 7.2, PHP 7.3 or PHP 7.4.
Visual C++ 16.0 (Visual Studio 2019) for master.

After the installation is complete, remember to install the "Desktop Development with C++" component. Remember to select Visual Studio according to the php development version, otherwise the generated components will not be available.

2. php-sdk-binary-tools selection

The current latest version is 2.2+. The reason for choosing 2.1.9 is that the version above 2.2 requires a 64-bit operating system.

reference link

1.Build your own PHP on Windows
2.PHP For Windows
3.php-sdk-binary-tools
4.Visual Studio 2019

Guess you like

Origin blog.csdn.net/a7442358/article/details/123707119