I use both PHP in a WAMP environment and code with both C++ and PHP. I'm just trying to develop my first PHP extension (Module), but have reached a brick wall. Maybe someone can help?
I'm running PHP 8.2.8 TS 64-bit through an Apache 2.4.x web server on Windows Server
I'm using:
Visual Studio 2022 using Windows SDK 10 and the same platform API as the PHP (API20220829)
Preprocessor definitions: ZEND_THREAD_SAFE; ZEND_WIN32; PHP_WIN32
Linked to: php8ts.php
Language Standard: ISO C++ 14
Runtime Library: Multi-threaded DLL (/MD)
It compiles, links and dlivers the php_helloworld.dll
I have chosen every option I can to produce a THREAD SAFE version and I am using the downloaded PHP8.2.8 TS 64-bit TS development pack. ( php-devel-pack-8.2.8-Win32-vs16-x64 ).
However, I get the following error every time, telling me it is NON THREAD SAFE.
_
PHP Warning: PHP Startup: php_helloworld: Unable to initialize module
Module compiled with build ID=API20220829,NTS,VS16
PHP compiled with build ID=API20220829,TS,VS16_
_
I have tried changes and tweaks to the configuration for 3 days and always the same result.
It is a very simple, single CPP file with following code, just to test it out:
// 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");
}
I'm completely stumped, so any positive advice or assistance gratefully received.