Hi!
I am having a big trouble trying to run a PHP4 extension module that calls a shared library, written basically in C++. The shared library uses internally a lot of STL-template classes calls, dynamic objects etc. To make it possible to link to C-code, I’ve made a function set (something like an API), using extern ”C” declaration modifiers, so there are no problems when linking to C-code. I’ve tested the library functioning by calling my API from a simple C-program. I’ve also pulled all global data out of the library, making it possible the caller to allocate the required amount of memory in “his” own heap. The library uses only dynamic allocation during execution (no global data at all), the general idea is to ensure thread-safety.
In the moment I call my functions from within the PHP4 module, I get a mysterious “segmentation fault” in apache. Actually, the situation is very strange. The initialization of my shared library, called in the module-init-function, goes OK, some dynamic memory is allocated, two files are opened & read into memory and so on, everything is OK (I’ve traced all steps). When restarting apache, shut-down is performed successfully, too. But when a browser calls the interface function from the PHP-module, which should call a function in the shared library, apache crashes immediately (a seg-fault 11 is logged). Using file logging, I found out that the PHP-module function is not even called.
My questions are: Are there some special considerations to observe when calling C++ libraries from PHP modules under Linux? Could anybody give a hint for this situation? What am I missing/not noticing?
I hope I’ve described the situation with enough details. In addition, here is some version information:
Debian Linux 2.2.17
gcc/g++ 2.95.2 20000220
PHP 4.0.3pl1
Apache 1.3.9
I hope I’ll receive a precise answer, thank you!
Best Regards,
Angel Sinigersky
P.S. The shared library is developed with Visual C++ 6 sp3 & carefully tested/traced there (in the beautiful environment :-); no memory leaks, abnormal behaviour etc. were found.