简体   繁体   中英

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

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 Startup: ÂÀL&À: Unable to initialize module Module compiled with module API=16777522 PHP compiled with module API=20090626 These options need to match in on line :PHP启动:“ L”:无法初始化模块使用模块API = 16777522编译的模块使用模块API = 20090626编译的PHP这些选项需要在第行的匹配

It seems that my PHP_API_VERSION is 20090626, but for some reason my DLL thinks it's PHP_API_VERSION is 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

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?

I am compiling the dll successfully with Borland C++ Builder v5.5, not Visual Studio.

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?

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

You should change the API version in zend_modules.h to the API version which your PHP server indicates in phpinfo().

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.

Sounds like you're compiling against a different version of PHP than the one you're running.

Take a peek in php.h and look for #define PHP_API_VERSION -- that's what you're compiling against.

Is that the same version that's running on your server?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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