hello everyone!
i'm having some problems during creation of an extension module. i need to create a new module to be used with some libraries which are not in the stock php.
as a test i followed the instructions on http://www.phpbuilder.com/manual/zend.creating.php and used the code there for the test module. the module code is as below:
#include "php.h"
ZEND_FUNCTION(test_module);
zend_function_entry testmod_functions[] =
{
ZEND_FE(test_module, NULL)
(NULL, NULL, NULL)
};
zend_module_entry testmod_module_entry =
{
STANDARD_MODULE_HEADER,
"Test Module",
testmod_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
/ implement standard "stub" routine to introduce ourselves to Zend /
#if COMPILE_DL_FIRST_MODULE
ZEND_GET_MODULE(testmod)
#endif
/ implement function that is meant to be made available to PHP /
ZEND_FUNCTION(test_module)
{
long parameter;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", ¶meter) == FAILURE)
{
return;
}
RETURN_LONG(parameter);
}
and then i compiled and linked the following code as below:
$ gcc -fpic -DCOMPILE_DL=1 -I/usr/local/php4.3.4/include/php -I/usr/local/p
hp4.3.4/include/php/main -I/usr/local/php4.3.4/include/php/regex -I/usr/local/php4.3.4/inc
lude/php/Zend -I/usr/local/php4.3.4/include/php/TSRM -c -o phpext.o phpext.c
$ gcc -shared -rdynamic -o phpext.so phpext.o
note that i installed php-4.3.4 with the prefix=/usr/local/php4.3.4
the php page which i tried to load the library is as follows
<?php
dl("phpext.so");
$param = 2;
$return = first_module($param);
print("We sent '$param' and got '$return'");
?>
i moved the phpext.so to the same directory as the above file.
when i tried to acces the above file, an error occured:
Warning: dl(): Unable to load dynamic library '/usr/local/php4.3.4/lib/php/extensions/no-d
ebug-non-zts-20020429/phpext.so' - /usr/local/php4.3.4/lib/php/extensions/no-debug-non-zts
-20020429/phpext.so: cannot open shared object file: No such file or directory in /home/pr
ojects/godfather/WEBAPP/ext.php on line 2
Fatal error: Call to undefined function: first_module() in /home/projects/godfather/WEBAPP
/ext.php on line 4
so i moved the phpext.so to /usr/local/php4.3.4/lib/php/extensions/no-debug-non-zts
-20020429 and this time the error was:
Warning: dl(): Invalid library (maybe not a PHP library) 'phpext.so' in /home/projects/god
father/WEBAPP/ext.php on line 2
Fatal error: Call to undefined function: first_module() in /home/projects/godfather/WEBAPP
/ext.php on line 4
although the compilation and the linking produced no warnings or errors, since all the code above i took directly from the examples, i have a feeling that something is amiss during the compiling and linking process. but i am unable to figure this out.
can anybody tell me which part i did wrong? thanks in advance.