The Linux Page

PHP Startup: Unable to load dynamic library http.so: undefined symbol: Z_ADDREF_P in Unknown on line 0

Today I helped a customer get a PECL extension going. The first error I was getting was as follow:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/http.so' - /usr/lib64/php/modules/http.so: cannot open shared object file: No such file or directory in Unknown on line 0

Obviously the extension was not yet installed... I run pear install pecl/pecl_http in order to get it to work, which it did after I installed the C compiler, the curl header files, and a few other things.

After a few minutes, I got the message:

install ok: channel://pecl.php.net/pecl_http-1.7.3

Sounds like the compiled went perfect! Now testing with php -v I am getting this error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/http.so' - /usr/lib64/php/modules/http.so: undefined symbol: Z_ADDREF_P in Unknown on line 0

The error is pretty clear. The HTTP extension was compiled, but it makes use of a function that does not exist in PHP. The function called Z_ADDREF_P (and also Z_ADDREF_PP) was added to PHP 5.3.0 and since the system I was working on has PHP 5.1.6, the function does not exist.

Actually, it is not a function, it is a macro that calls the zcat_addref_p() function. By the way, the Z stands for Zend, in case you had not figured it out yet...

This is the same function as the ZVAL_ADDREF() macro, as far as I can tell, just cleaner to use. The guys creating the HTTP module thought of that so they defined a missing.h file, but they did not (yet) define a Z_ADDREF_P() equivalent...

On my end, I declared that new macro in /usr/include/php/main/php.h the exact same way as the old one:

#ifndef Z_ADDREF_P
#define Z_ADDREF_P(pz)     (++(pz)->refcount)
#endif

I will know later if that causes problems, but so far so good... it compiled and loads perfectly. Whether it runs is a different question. I'll update this post as required as I hear about the problem further.

Reference: PHP e-Fax manual

Re: PHP Startup: Unable to load dynamic library http.so: ...

Thank you Jeremy for sharing your solution.

I never bothered to get the correct md5sum since I know what I'm doing, but that's certainly a good idea (if you also save it on another computer that's not accessible from the main server.)

Alexis

Re: PHP Startup: Unable to load dynamic library http.so: ...

I had to use a similar method for a configuration I'm using as well. I've included some enhanced instructions below:

mkdir pecl
cp pecl_http-1.7.3.tgz pecl
cd pecl
tar –xvf pecl_http-1.7.3.tgz
cd pecl_http-1.7.3
vi php_http.h

#add right under comments:

#ifndef Z_ADDREF_P
#define Z_ADDREF_P(pz) (++(pz)->refcount)
#endif

#save

md5sum php_http.h

#copy value

cd ..
vi package.xml

#replace prior php_http.h value with new value

rm pecl_http-1.7.3.tgz
tar -zcvf pecl_http-1.7.3.tgz package.xml pecl_http-1.7.3

#remove old version
pear uninstall pecl_http-1.7.3
pear install pecl_http-1.7.3.tgz