I've followed a tutorial for making php extensions in C++ and although there are no compilation errors, the extension just won't communicate with php. The tutorial is at http://www.talkphp.com/vbarticles.php?do=article&articleid=49&title=creating-custom-php-extensions and my code is as follows:


#include "stdafx.h" 


zend_function_entry talkphp_ext_functions[] = { 
    ZEND_FE(fetch_talkphp_links, NULL) 

zend_module_entry talkphp_ext_module_entry = { 
    "TalkPHP Extension", 


    bool useHtml = false; 
    char *link = ""; 

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &useHtml) == FAILURE) 
        RETURN_STRING("Missing Parameter", true); 

    if (useHtml == true) 
        link = "<a href=\"http://www.talkphp.com\">Visit TalkPHP.com!</a>"; 
        link = "http://www.talkphp.com"; 

    RETURN_STRING(link, true); 


#pragma once 

// Include the Zend Win32 header and the general PHP header 
#include "zend_config.w32.h" 
#include "php.h"

Php Code:

echo fetch_talkphp_links(true);


Fatal error: Call to undefined function fetch_talkphp_links()...

Also, I have rebooted apachie and recompiled this code many times and yet still it will not communicate with php. I have even double checked and re-checked the tutorial to make sure I haven't done anything wrong. And I'm using Visual C++ 2008 with Windows XP Pro and PHP 5.
I just can't see any reason why the extension won't communicate with php. Any alternative tutorials for making php extensions in c++ are welcome as I have also tried replacing the code with code from a second tutorial without any luck. It's almost as if php needs something enabled even though I've added extension=php_talkphp.dll to the php.ini
Also I have confimed the location of the php.ini with php_info() function but the new extension doesn't show in that function. Any ideas to add this dll to php so that php recognises it?

Anybody at all because this error is really beginning to annoy me. I have followed 3 tutorials all resulting with the same problem. It seems theres something either in the Visual C++ settings or php.ini making the extension unable to communicate with php. I've been spending day and night, every piece of my spair time to try and solve this problem and although I have eliminated all the #define bugs in php itself as reported on the internet, it seems like if there is a missing link between the dll and php. With the exploration of this error, I now understand exactly how the c++ code works and what most of the Visuall C++ options mean.
Also I have tried using C code instead of C++ code and yet the same problem occures. The only modification in the php.ini file was extension=php_talkphp.dll so does anybody have any idea of what this might be?

Did you call php_info() to see if your extension was loaded or not?

I checked that each time I re-added the extension and it is not listed under php_info() even though it's in the php.ini file. The php.ini file I located from php_info(). I don't understand why php can't read it when I have followed the tutorials accurately.


Try loading the module at runtime using dl(). It should provide you with a warning about why the module couldn't be loaded

I tried using dl but since I'm running it on Windows XP, it has an error message saying the operating system is multi-threaded. The message is as follows:

Warning: dl() [function.dl]: Not supported in multithreaded Web servers...

Is there by any chance an existing extension that will do the same as dl() but for windows to help determine the error?

I have tested "Making PHP Extension in C++" successfully. I had used - XAMPP, Source code of PHP (downloaded separately), and VS2008.

Then could you please send the folder that contains the project as a zip so I can check what I did wrong.

Please find the .zip file

commented: Great information in short time +4

I just set the library paths and compiled your project but the following error came up:

1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(620) : warning C4273: 'getwchar' : inconsistent dll linkage
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(435) : see previous definition of 'getwchar'

1>c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(622) : warning C4273: 'putwchar' : inconsistent dll linkage
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(437) : see previous definition of 'putwchar'

1>c:\documents and settings\owner\my documents\visual studio 2008\projects\test\phpfiles\tsrm\tsrm_config_common.h(5) : fatal error C1017: invalid integer constant expression

I just googled the last error which is the only fatal error and it turns out to be a common one which I am trying to find a work around. But thanks for the source as I didn't have those original files and I kept the old preprocessor definitions which I now know more about. Any suggestions are welcome as I google this problem.

Make following changes in "tsrm_config_common.h".

to do this:

#ifdef TSRM_WIN32
# include "tsrm_config.w32.h"
# include <tsrm_config.h>
# include <sys/param.h>

So do I delete the lines before the occurance of that code?

PS: I just tried replacing the whole file with that code and 101 warnings came up but zero errors and php didn't recornise it. That is when I replace the entire file with that code.

So do I delete the lines before the occurance of that code?

PS: I just tried replacing the whole file with that code and 101 warnings came up but zero errors and php didn't recornise it. That is when I replace the entire file with that code.

I got two warning and an error. Error is solved when I remove some lines and the corrected code which I posted.

I have XAMPP; I have changed php.ini (for extension entry) which is located at apache\bin.

Could you please post the file to hopefully solve this one because I've been changing it by commenting sections but I just keep on getting the linker warnings unless I use the original file in which case is a single error.

I meant the tsrm_config_common.h file. Just that I can't get my head around the modifications since I'm unsure of exactly what to change.

Do not work on the code I have posted because the include directory and liker path are belongs to my computer.

for example, Path of file is E:\Source\php\php-5.2.9\TSRM\tsrm_config_common.h

I have just tried the dll you posted and it doesn't show up in the php_info(). To install it I simply added extension=php_talkphp.dll to the extension list and placed the dll in the etc/ directory. I am also using Xampp and located the php.ini at apachie/bin/. Comfirmed the location with php_info() and yet the module just won't load. I have also tried rebooting both apachie and the computer but the dll you gave me just won't work. Am I not doing something.

Try to modify php.ini in your windows folder.

I just check the windows folder for the php.ini and there isn't any in the windows folder. Also, I just tried adding the extension to every php.ini file on the computer and still no result.

Bad luck, dude. Be positive and start the action again.

Can you provide the running code of it? I am also creating extensions and need this running code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.