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:
main.cpp
#include "stdafx.h"
ZEND_FUNCTION(fetch_talkphp_links);
zend_function_entry talkphp_ext_functions[] = {
ZEND_FE(fetch_talkphp_links, NULL)
{NULL, NULL, NULL}
};
zend_module_entry talkphp_ext_module_entry = {
STANDARD_MODULE_HEADER,
"TalkPHP Extension",
talkphp_ext_functions,
NULL, NULL, NULL, NULL, NULL,
"1.0",
STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(talkphp_ext);
ZEND_FUNCTION(fetch_talkphp_links)
{
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>";
}
else
{
link = "http://www.talkphp.com";
}
RETURN_STRING(link, true);
}
stdafx.h
#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);
?>
Error:
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?