mongo-php-driver: Undefined Symbol php_json_serializable_ce in Unknown on Line 0 (1.2.0 Release)

Description

When installing mongodb from pecl on debian jessie, the extension seems to install fine but is never initialized due to this error. I regularly build from pecl, but right after today’s update all my build scripts broke for all my enviroments. Installing the actual extension works fine, but the extension is never loaded due to the error below.

Environment

Debootstrap Debian Jessie running PHP 5.6.27

root@b0277afcbe10:/# php -m                                                                                                                                                                                                                 
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20131226/mongodb.so' - /usr/lib/php5/20131226/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache

root@b0277afcbe10:/# php -i | grep -E 'mongodb|libmongoc|libbson'
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20131226/mongodb.so' - /usr/lib/php5/20131226/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0

Test Script

When trying to use the mongodb/mongodb package from Composer it throws:

( ! ) Fatal error: Class ‘MongoDB\Driver\Manager’ not found in /var/www/html/vendor/mongodb/mongodb/src/Client.php on line 61

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Fair enough, I just figured I would document it here regardless just in case someone else runs into the issue.

@derick, additional notice, from a quick search, php_json_serializable_ce is part of json public API since 5.4.26 and 5.5.10 and 5.6.0, so older version are not compatible (perhaps work if everything build statically)

P.S. http://git.php.net/?p=php-src.git;a=commitdiff;h=786234d351c40a9b4808d1dd13d2f91f2f5314be

@yaziderman if you use PHP 5.4.16 from CentOS official repository, you should use php-pecl-mongodb from EPEL repository (if you use any other packaged PHP version, ask your RPM provider).

This issue occurred to me when I was upgraded my PHP version. Previously I was using the PHP 5.4 and mongodb-1.2.0. When I upgraded to PHP 5.6 I got this problem. I installed mongodb-1.3.4 to fix this issue and it works fine.

PHP’s normal build system compiles in the JSON extension, by default, and statically. With that, the mongodb.so extension should build and load just fine.

Distributions often change from PHP’s normal practice, and compile extensions such as the JSON extensions as shared objects. They also provide the separate INI configuration files. When compiling and installing extensions from source, through PECL, we can’t it make to create these INI files. We do however say that the mongodb extension depends on the json extension, and with PHP’s normal extension loading mechanism, this should not cause a problem (but I will need to test/check that). I believe Debian (and RedHat/Fedora) change the shared object loading mechanism to use RTLD_NOW instead of the normal RTLD_LAZY, which would cause the problem here. I will also need to verify that.

In short, I am not sure whether we can do anything about that code wise, except for documenting that the mongodb extension can only be loaded after the json extension has been loaded.

Thanks for your query, could you please answer the following questions:

How are you loading the json extension?

Through a module?

Does it work if you load the json extension through the php.ini system before the mongodb extension?

What’s the output of php --ini