Reputation: 6833
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
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
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?
Upvotes: 1
Views: 1652
Reputation: 2145
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.
Upvotes: 0
Reputation: 6833
It turns out it was the "Data Alignment" - My DLL was being compiled using "Word" alignment and it needed to be double-word.
Upvotes: 1
Reputation: 10992
Check your include paths, locate file php.h and check that the version there matches php that you are running (running version is found if you check phpinfo() output).
Upvotes: 0
Reputation: 62864
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?
Upvotes: 0