PHP extension module problem

php.internals

Pascal dev

21 years ago
Hello, I am actually working on a PHP extension module writen in C and I have a problem I cannot resolve for weeks : it runs perfectly when PHP is configured as a CGI script but not when PHP is an Apache module (httpd is no more responding after a few requests). Configuration: OS: Linux 2.4.20-8 Redhat 9 Server: Apache 2 configured with mpm=prefork PHP: 4.3.2 or 4.3.3 or PHP 5 (same problem) Module presentation: Developped in C, the module.so is placed in the /usr/local/lib/php/extensions/no-debug-non-zts-20020429/ directory All the PHP scripts begin with: dl('module.so'); I also tried to add extension=module.so in the php.ini file and remove the dl instruction : same problem Problem description: If PHP is compiled with '--enable-force-cgi-redirect' and is a CGI script, everything is ok If PHP is compiled with '--with-apxs2=/usr/local/apache2/bin/apxs' and is an Apache module, only a few requests are ok (the first one and sometime one more). When attempting another request, the httpd is not responding and the logs in my application show me that it stopped processing during execution of my program. If I changed the C program, it will stop at another point as if something was wrong in the memory and the problem could appear at any moment... I have read and read the PHP manual to find out information.... I though about a lot of possibilities : -problem with C global variable handling (I am not using ZTS), -problem with Zend variables handling (the C functions are creating and updating zval parameters) -problem with sessions (I tried files and mm with same result) -bad configuration... I could give more information if needed. Anyway, I thank you for the time you will spend reading this email. Pascal

Rasmus Lerdorf

21 years ago
On Thu, 28 Oct 2004, Pascal dev wrote:
> I though about a lot of possibilities : > -problem with C global variable handling (I am not using ZTS), > -problem with Zend variables handling (the C functions are creating and updating zval parameters) > -problem with sessions (I tried files and mm with same result) > -bad configuration...
Sounds more like some nasty memory handling problem to me. When running as a CGI your process starts up and shuts down completely for each request so the OS cleans everything up for you after each request even if you forget to free() malloc'ed memory. When running as an Apache module your code must be re-entrant and clean up after itself after each request. If you use PHP's emalloc/efree memory handling wrappers this is easy, but if you are doing your own mallocs perhaps you forgot to free and on each request you chew up more memory. Pop it through Valgrind and see what is happening. -Rasmus