在 Visual C++ 中为 PHP8.2.8 编写线程安全 PHP 扩展

问题描述 投票:0回答:0

我正在尝试(但失败了)生成一个线程安全的 PHP 扩展 DLL。

我在 WAMP 环境中使用 PHP,并使用 C++ 和 PHP 编写代码。现在,我只是尝试在 Visual C++ 中开发我的第一个 PHP 扩展(模块),但已经遇到了瓶颈。

也许有人可以帮忙?

我完全被难住了,因此非常感谢任何积极的建议或帮助。

我通过 Windows Server 上的 Apache 2.4.x Web 服务器运行 PHP 8.2.8 TS 64 位 我在用着: 使用 Windows SDK 10 和与 PHP 相同平台 API 的 Visual Studio 2022 (API20220829)

预处理器定义:ZEND_THREAD_SAFE; ZEND_WIN32; PHP_WIN32 链接到:php8ts.php

语言标准:ISO C++ 14

运行时库:多线程DLL(/MD)

它编译、链接并传递 php_helloworld.dll

我已经选择了所有可以选择的选项来生成 THREAD SAFE 版本,并且我正在使用下载的 PHP8.2.8 TS 64 位 TS 开发包。 ( php-devel-pack-8.2.8-Win32-vs16-x64 ).

但是,我每次都会收到以下错误,告诉我这是非线程安全

PHP 警告:PHP 启动:php_helloworld:无法初始化模块:

使用构建 ID=API20220829 编译的模块,NTS,VS16

使用构建 ID=API20220829 编译的 PHP,TS,VS16

我已经尝试更改和调整配置 3 天,结果始终相同。

这是一个非常简单的单个 CPP 文件,代码如下,只是为了测试一下:

// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "php.h"

#define ZEND_DEBUG 0

// Declare the function
PHP_FUNCTION(php_helloworld);

// register our function to the PHP API
// so that PHP knows, which functions are in this module
zend_function_entry php_helloworld_functions[] =
{
PHP_FE(php_helloworld, NULL)
{
NULL, NULL, NULL
}
};

// some pieces of information about our module
zend_module_entry php_helloworld_module_entry =
{
STANDARD_MODULE_HEADER,
"php_helloworld", // Extension name
php_helloworld_functions, // Function entry
NULL, // Module initialization
NULL, // Module shutdown
NULL, // Request initialization (not used)
NULL, // Request shutdown (not used)
NULL, // Extension info (not used)
"1.0", // Extension version
STANDARD_MODULE_PROPERTIES
};

// use a macro to output additional C code, to make ext dynamically loadable
ZEND_GET_MODULE(php_helloworld)

// Finally, we implement our "Hello World" function
// this function will be made available to PHP
// and prints to PHP stdout using printf
PHP_FUNCTION(php_helloworld)
{
php_printf("Hello World! (from our extension)\n");
}

php visual-c++ php-extension
© www.soinside.com 2019 - 2024. All rights reserved.