[PCBC-112] "undefined symbol: php_json_decode in Unknown on line 0" when load couchbase.so library Created: 10/Sep/12  Updated: 25/Jan/13  Resolved: 29/Nov/12

Status: Resolved
Project: Couchbase PHP client library
Component/s: library
Affects Version/s: None
Fix Version/s: None
Security Level: Public

Type: Bug Priority: Major
Reporter: thanhbv Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: centos 6.3 x86_64

php 5.4 from remi repository ( http://blog.famillecollet.com/en )
# rpm -q php-fpm
php-fpm-5.4.6-1.el6.remi.x86_64

# uname -a
Linux dhcppc0 2.6.32-279.5.2.el6.x86_64 #1 SMP Fri Aug 24 01:07:11 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Attachments: HTML File phpinfo.html    

 Description   
Affects Versions:
1.0.6-1
1.1.0dp9-1

Here are steps to reproduce error in version 1.0.6-1, (version 1.1.0dp9-1 is similar):
1. create file /etc/yum.repos.d/couchbase.repo

[couchbase]
name = Couchbase package repository
# baseurl = http://packages.couchbase.com/rpm/6.2/x86_64
baseurl = http://packages.couchbase.com/preview/rpm/5.5/x86_64
gpgcheck=0

2. yum install libcouchbase1

3.
# wget http://packages.couchbase.com/clients/php/php-ext-couchbase-1.0.5-centos62-x86_64.tar.gz
# tar xzf php-ext-couchbase-1.0.5-centos62-x86_64.tar.gz
# cp php-ext-couchbase/couchbase.so /usr/lib64/php/modules/

4. add the following line to /etc/php.d/json.ini:
extension=couchbase.so

5. # service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [10-Sep-2012 17:42:45] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/couchbase.so' - /usr/lib64/php/modules/couchbase.so: undefined symbol: php_json_decode in Unknown on line 0
                                                           [ OK ]



 Comments   
Comment by Matt Ingenthron [ 11/Sep/12 ]
This is not a bug.

This is an issue with the order of the extensions, and it's mentioned in the installation section on http://www.couchbase.com/develop/php/current

Solution is to put the extension in a different .ini file.
Comment by thanhbv [ 12/Sep/12 ]
No. I think this is a new bug.
Have you read carefully the error description above?

The installation document say that:
"The easiest workaround if you encounter this is to edit the ini file that loads the JSON extension (typically /etc/php.d/json.ini) and add the Couchbase extension after the JSON extension."

Not " put the extension in a different .ini file".

OK. I will describe more detail:
1.
~2 month ago, in one of my server, running centos 6.2 & php 5.4, couchbase-server 1.8.0, I have install this php extension successfully:
a. If I add "extension=couchbase.so" in /etc/php.d/couchbase.ini => error.
b. If I put "extension=couchbase.so" in /etc/php.d/zzcouchbase.ini, OR add "extension=couchbase.so" to the end of /etc/php.d/json.ini => success.

2. Yesterday, In my other server with centos to 6.3, php-5.4.6-1.el6.remi.x86_64 (newer than the php package in my first server), couchbase-server 1.8.1 => this error (even if I config as in session 1.b above!)

Then, I think you should try the steps above before closing this issue.
thank you.
Comment by Mark Nunberg [ 12/Sep/12 ]
The problem would be in your PHP configuration.

The json function not found is actually compiled into PHP, and should be present (in Debian's 5.4 it's there as part of the binary).

The extension code compiles out references to php_json_* if it's not defined in PHP's own header files. If you do a simple search for php_json here https://github.com/couchbase/php-ext-couchbase/blob/master/couchbase.c you'll see there isn't a place where php_json_* is mentioned without #define guards ensuring it doesn't work on non-JSONified PHPs.

I am not familiar with the specific RPM you're using.. let me check that out..
Comment by Matt Ingenthron [ 12/Sep/12 ]
Typically issues with undefined symbols indicate either an order of loading libraries problem or something like using 32-bit binaries on a 64-bit system. In this particular case, you're reporting that it can't load the symbol for php_json_decode. Since we don't ship php_json_decode, it's either missing from your install, you're loading in the wrong order or you're loading the wrong architecture.

My guess is that you may not have the php_json_decode for some reason. We test this on stock CentOS 6.2 before shipping, and we would have caught a symbol resolution then.

Do you still have this issue with stock PHP from the standard CentOS 6 repository? If so, we can look into it further.
Comment by thanhbv [ 15/Sep/12 ]
I have just attached file phpinfo.html.

I use PHP 5.4. The stock PHP from the standard CentOS 6 repository is only 5.3.3

Now, I must use php-pecl-memcached-2.1.0-2.el6.remi.1.x86_64 as a workaround
Comment by thanhbv [ 28/Sep/12 ]
If I build from souce then it work as expected:

$ git clone https://github.com/couchbase/php-ext-couchbase.git
$ cd php-ext-couchbase
# yum --enablerepo=remi,remi-test install php-devel
$ phpize
$ ./configure
$ make
$ make test
$ make install
# echo 'extension=couchbase.so' > /etc/php.d/zzcouchbase.ini
# service php-fpm restart
Comment by Matt Ingenthron [ 25/Oct/12 ]
This appears to have been a problem with the specific PHP version in use, and we've not been able to reproduce it with stock PHP. We plan to add testing for 5.4 soon.
Comment by Matt Ingenthron [ 27/Nov/12 ]
In the end, this is NOT an issue with php 5.4, but rather an issue with some distributions of PHP not including core functionality. This has been confirmed by the PHP core team.

To address this, we're adding some documentation (see PCBC-141). Here's a summary from the discussion on the documentation (Thanks to Mark Nunberg).

------------
PHP distributions which have JSON *built in*, (This includes Debian-based distributions, and Windows binary releases), the only thing required is to have a *SINGLE* line
extension=couchbase.so
For PHP distributions which have JSON as a *module* (This includes Red Hat EL-based distributions, as noted above), there are two required lines in this very
extension=json.so
extension=couchbase.so

[ As a side note, for Windows users, one might need to substitute 'couchbase.so' with 'couchbase.dll', or 'php_couchbase.dll' (not sure which one) ].

We will refer to these incantations (for the purpose of this discussion thread) as 'one-line' and 'two-line'

If one places a one-line incantation where the two-line is required, they will get a cryptic message to the effect of:

unable to load couchbase.so: cannot find symbol 'php_json_decode'
(the exact text might be different.. I will try and give an exact quote). At which point the couchbase extension will be unavailable)

If one places the two-line incantation where a one-line is required, they will receive a harmless warning stating:

extension 'json' already loaded
(again, this might not be the exact text)
--------

Comment by Perry Krug [ 29/Nov/12 ]
So this needs to be reopened right? because it requires us to build a specific a package for RHEL 5.4?
Comment by Matt Ingenthron [ 29/Nov/12 ]
Correct, needs to be reopened.

A workaround for now would be to download the PHP 1.0.6 source, build, test and release. Source is available from:
https://github.com/couchbase/php-ext-couchbase/archive/1.0.6.tar.gz

The included README covers how to build/test. It does require a php development environment, which is a separate package on RH. Usually I think it's php54-devel, but I'd have to check.
Comment by Matt Ingenthron [ 29/Nov/12 ]
Though, I should have said, I think in this original bug, there were multiple issues. I'm going to close this one and open a specific issue for support of PHP 5.4.
Comment by Matt Ingenthron [ 29/Nov/12 ]
See tracking of support of PHP 5.4 in PCBC-151.
Comment by Igal Alkon [ 25/Jan/13 ]
I just had the same issue when install on CentOS 6.3
the solution thanhbv offered worked although all tested failed !
i did:
make install
mv /etc/php.d/json.ini /etc/php.d/0json.ini

then phpinfo();
[root@null ~]# php phpinfo.php | grep couch
/etc/php.d/couchbase.ini,
couchbase
couchbase support => enabled
couchbase.compression_factor => 1.3 => 1.3
couchbase.compression_threshold => 2000 => 2000
couchbase.compressor => none => none
couchbase.durability_default_poll_interval => 100000 => 100000
couchbase.durability_default_timeout => 40000000 => 40000000
couchbase.serializer => php => php
couchbase.view_timeout => 75 => 75
OLDPWD => /root/php-ext-couchbase
_SERVER["OLDPWD"] => /root/php-ext-couchbase

Using the compiled one from the site did not work.
Generated at Tue Jul 22 19:58:55 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.