[nycphp-talk] problems loading a custom, shared extension
Hans Zaunere
lists at zaunere.com
Sun Dec 18 21:05:43 EST 2005
Jonathan wrote on Thursday, December 08, 2005 12:28 AM:
> I need help figuring out an error when writing/loading a custom, shared
> extension (.so) for PHP.
> Could anyone help or recommend good links, books, or other mailing lists
> for developing in C to extend PHP?
>
> I have "Building Custom PHP Extensions" by Blake Schwendiman and
> "Advanced PHP Programming" by George Schlossnagle (9432 times mentioned
> on this list). Both excellent books which got me started, but looking for
> more information. I've been around the Zend Dev site and
> http://talks.php.net/ (http://www.zend.com/apidoc/ as well) but I am
> stuck.
>
> Thank you.
>
> Background:
> -------------
> I am writing a script in C that uses shared memory and/or memory-mapped
> files to (attempt to) speed up some frequently used PHP functionality.
> I need to test the speed of the extension (using some apache "ab"
> scripts) in environments where the extension will be loaded via the ini
> rather than being compiled into php.
>
> Summary of Problem:
> ----------
> The extension will compile into PHP 4.4.1 and runs without issue as a
> compiled-in extension.
> I can build it into a shared object using phpize for both 4.4.1 source
> and the 4.3.11 binaries.
> I get no errors running phpize.
> In both the PHP.INI context and dl() context the only error message is (
> it can, at least, find the .so): "PHP Warning: Unknown(): Invalid
> library (maybe not a PHP library) 'my_ext.so' in Unknown on line 0"
>
> Details:
> -----------
> Linux, Fedora Core 4. GCC 4.0.x
>
> dl() fails to load the .so in CLI with php of the same version (perhaps
> it fails because it is already an internal extension?)
> dl() AND loading through the INI fail in a server (Apache 2.0.x) with a
> different version of php (4.3.11) . php.ini. (I run phpize that is
> included with the precompiled 4.3.11 and added the 3 headers it needs. )
> Only error message is at load time ( it can, at least, find the .so):
>
> "PHP Warning: Unknown(): Invalid library (maybe not a PHP library)
> 'my_ext.so' in Unknown on line 0"
This would involve some more debugging, but perhaps here are some things to
keep in mind:
-- you might get symbol conflicts if the extension is compiled in and also
loaded with dl(); do one or the other
-- I've noticed that PHP extensions are quite sensitive to the PHP and Zend
Engine versions. Be sure you're using the same versions of phpize and the
running PHP. Pay attention to the top section of phpinfo()'s outout (fields
like PHP API, PHP Extension, Zend Extension).
Best,
---
Hans Zaunere / President / New York PHP
www.nyphp.org / www.nyphp.com
More information about the talk
mailing list