configuring dynamic extensions
| From: | Randy Debasa | Date: | Mon, 15 Mar 2004 17:07:50 +0000 |
| Subject: | configuring dynamic extensions | ||
| Groups: | php.install | ||
| Request: | Send a blank email to php-install+get-12986@lists.php.net to get a copy of this message | ||
We are using php-4.3.2 and Apache 2.
Here is exactly what we did:
First we created this cpp source file:
------------------------------------------------------------------
#include "php.h"
/* declaration of functions to be exported */
ZEND_FUNCTION(first_module);
/* compiled function list so Zend knows what's in this module */
zend_function_entry firstmod_functions[] =
{
ZEND_FE(first_module, NULL)
{NULL, NULL, NULL}
};
/* compiled module information */
zend_module_entry firstmod_module_entry =
{
STANDARD_MODULE_HEADER,
"First Module",
firstmod_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(firstmod)
#endif
/* implement function that is meant to be made available to PHP */
ZEND_FUNCTION(first_module)
{
long parameter;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
¶meter) == FAILURE) {
return;
}
RETURN_LONG(parameter);
}
After creating the first_module.cpp file above we compiled it and linked
it using the following commands:
$ g++ -fpic -DCOMPILE_DL_FIRST_MODULE=1 -I/usr/include/php/main/
-I/usr/include/php/Zend/ -I/usr/include/php/ -I/usr/include/php/TSRM/ -c
-o first_module.o first_module.cpp
$ g++ -shared -L/usr/local/lib -rdynamic -o first_module.so
first_module.o
Then, we checked in php.ini file for the extension directory
(phpinfo()), which happened to be :
/usr/local/lib/php/extensions/no-debug-non-zts-20020429/
We also made sure that enable_dl was On.
We copied the first_module.so file into the extension directory.
We then tested the first_module.so file using the following php page:
<?php
print("Beginning");
dl("first_module.so");
$param = 2;
$return = first_module($param);
print("We sent '$param' and got '$return'");
print("Done...");
?>
This is the error we are getting:
Beginning
Warning: dl(): Invalid library (maybe not a PHP library)
'first_module.so' in /home/randy/public_html/index.php on line 3
Fatal error: Call to undefined function: first_module() in
/home/randy/public_html/index.php on line 6
Is there anything else that we need to do to be able to use a dynamic
loadable module??
Any help will be greatly appreciated!!!
-rdebasa