简体   繁体   English

在Windows上使用正确的API版本编译PHP扩展

[英]Compiling PHP Extension with correct API Version on Windows

I have finally created a very simple "Hello World" style PHP Extension dll on windows, after immeasurable hassle. 经过无可估量的麻烦之后,我终于在Windows上创建了一个非常简单的“ Hello World”风格的PHP扩展dll。 However, although I have successfully created a DLL, and put it in the extensions folder, and told php.ini about it, now I get this: 但是,尽管我已经成功创建了一个DLL,并将其放在extensions文件夹中,并告诉了php.ini,现在我得到了:

PHP Warning: PHP Startup: \\x81\\xc2\\xc0\\x03L&\\xc0\\x03: Unable to initialize module\\nModule compiled with module API=16777522\\nPHP compiled with module API=20090626\\nThese options need to match\\n in Unknown on line 0 PHP警告:PHP启动:\\ x81 \\ xc2 \\ xc0 \\ x03L&\\ xc0 \\ x03:无法初始化模块\\ n使用模块API = 16777522编译的模块\\ n使用模块API = 20090626编译的PHP \\ n这些选项需要匹配\\ n in Unknown on 0行
Warning : PHP Startup: ÂÀL&À: Unable to initialize module Module compiled with module API=16777522 PHP compiled with module API=20090626 These options need to match in Unknown on line 0 警告 :PHP启动:“ L”:无法初始化模块使用模块API = 16777522编译的模块使用模块API = 20090626编译的PHP这些选项需要在第0行的未知中匹配

It seems that my PHP_API_VERSION is 20090626, but for some reason my DLL thinks it's PHP_API_VERSION is 16777522. 看来我的PHP_API_VERSION是20090626,但是由于某种原因,我的DLL认为它的PHP_API_VERSION是16777522。

The tutorial below was some help in compiling an extension dll: http://www.talkphp.com/vbarticles.php?do=article&articleid=49&title=creating-custom-php-extensions 以下教程在编译扩展dll时提供了一些帮助: http ://www.talkphp.com/vbarticles.php?do = article&articleid = 49&title = creating-custom-php-extensions

Having written it myself, I have access to all of the source code for the php extension in question - But, where is it that I control the PHP_API_VERSION that ends up in the DLL? 自己编写完代码后,我就可以访问有关php扩展的所有源代码-但是,我控制在DLL中终止的PHP_API_VERSION在哪里呢?

I am compiling the dll successfully with Borland C++ Builder v5.5, not Visual Studio. 我正在使用Borland C ++ Builder v5.5(不是Visual Studio)成功编译dll。

Here is the complete source, in case it matters: 如果需要的话,这里是完整的资源:

// Needed to make following two #includes compatible with borland header files
void __fastcall __assume(int t) {
  return;
}
typedef unsigned int socklen_t;
typedef enum BOOL
{
  false=0,
  true
} bool;
// end Borland compatibility code

#include "php.h"
#include "zend_config.w32.h"
ZEND_FUNCTION(fetch_LinkGrammar_links);

zend_function_entry LinkGrammar_ext_functions[] = {
    ZEND_FE(fetch_LinkGrammar_links, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry LinkGrammar_ext_module_entry = {
    STANDARD_MODULE_HEADER,
    "LinkGrammar Extension",
    LinkGrammar_ext_functions,
    NULL, NULL, NULL, NULL, NULL,
    "1.0",
    STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(LinkGrammar_ext);

ZEND_FUNCTION(fetch_LinkGrammar_links)
{
    bool World = false;
    char *RetVal= "";
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &World) == FAILURE)
    {
        RETURN_STRING("Missing Parameter", true);
    }
    if (World == true)
    {
        RetVal= "Hello World";
    }
    else
    {
        RetVal= "Hello";
    }

    RETURN_STRING(RetVal, true);
}

What can I change to eliminate the PHP Startup Error that the API must match? 我该如何更改以消除API必须匹配的PHP启动错误?

原来是“数据对齐”-我的DLL是使用“字”对齐进行编译的,它需要是双字的。

You should change the API version in zend_modules.h to the API version which your PHP server indicates in phpinfo(). 您应该将zend_modules.h中的API版本更改为PHP服务器在phpinfo()中指示的API版本。

For example if the PHP Extension API in phpinfo() is 20090523, you should change the API number in zend_modules.h file to 20090523 and then rebuild your project. 例如,如果phpinfo()中的PHP扩展API为20090523,则应将zend_modules.h文件中的API编号更改为20090523,然后重新构建项目。

Sounds like you're compiling against a different version of PHP than the one you're running. 听起来您正在针对与运行版本不同的PHP版本进行编译。

Take a peek in php.h and look for #define PHP_API_VERSION -- that's what you're compiling against. 窥视php.h并查找#define PHP_API_VERSION -这就是您要编译的对象。

Is that the same version that's running on your server? 该版本与服务器上运行的版本是否相同?

检查您的包含路径,找到文件php.h并检查那里的版本是否与您正在运行的php匹配(如果您检查phpinfo()输出,则会找到正在运行的版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM