I installed memcache in the following way:
1) yum install memcached 2) yum install php-pecl-memcached 3) Also enabled the 'memcached.so' in php.ini
I tested the memcached in the follwing way:
$mc = new Memcache; $mc->addServer('localhost', 11211); echo "Server's version: " . $mc->getVersion() ;
But it generates the following error:
PHP Warning: PHP Startup: Unable to l开发者_Go百科oad dynamic library '/usr/lib64/php/modules/memcached.so' - /usr/lib64/php/modules/memcached.so: undefined symbol: php_json_encode in Unknown on line 0 PHP Fatal error: Class 'Memcache' not found in /root/memcacheTest.php on line 2
Thank u.
I don't know PHP well (or at all), but from the error message I'll hazzard a guess that you do not have the PHP JSON extension installed, which is apparently needed by the memchached extension.
Apparently, the JSON extension has been in PHP since version 5.2.0, therefore:
- You have an older version and you need to upgrade or install the JSON extension yourself
or
- Your operating system distributor supplies the PHP JSON extension in a different package that you have not installed.
There is of course the possibility of a misconfiguration, but I think it's slightly less likely.
This showed memcached.so didn't loaded successfully.
Error shows the reason: json.so should be load before memcached.so
Please use php -m | grep memcached
to check whether memcached.so is loaded successfully.
- If show
memcached
, this mean it succeeded. - If show like
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/memcached.so' - /usr/lib64/php/modules/memcached.so: undefined symbol: php_json_decode_ex in Unknown on line 0
Here is the solusion: e.g your php.ini is /etc/php.ini, your php.d is /etc/php.d/
Solution 1
- comment 'memcached.so' in php.ini
vim /etc/php.d/memcached.ini
- add
extension=memcached.so
in /memcached.ini php -m | grep memcached
check whether memcached is succeed loaded
Solution 2
rm /etc/php.d/json.ini
- add
extension=json.so
in php.in beforeextension=memcached.so
php -m | grep memcached
check whether memcached is succeed loaded
Can you check and double check user permissions? Additionally, my experience with PHP is that the distribution repository versions of PHP aren't very good. I solved those symbol errors by compiling PHP from the ground up. But that's a very radical and time-consuming solution.
http://pecl.php.net/bugs/bug.php?id=17574&edit=1
Just make sure that extension=json.so is specified BEFORE extension=memcached.so.
I had placed extension=memcached.so in php.ini, and extension=json.so was specified in /etc/php.d/json.ini, that is parsed AFTER php.ini. That is why PHP can't find php_json_encode() at the point of loading memcached.so.
Also, check that the permissions on memcached.so are the same as the other extensions
Try to install the version 2.0. It helped for me.
yum -y install gcc-c++
wget http://launchpad.net/libmemcached/1.0/0.50/+download/libmemcached-0.50.tar.gz
tar xzf libmemcached-0.50.tar.gz
cd libmemcached-0.50
./configure
make
make install
wget http://pecl.php.net/get/memcached-2.0.0b2.tgz
pecl install memcached-2.0.0b2.tgz
echo 'extension=memcached.so' > /etc/php.d/memcached.ini
service php-fpm restart
cd ..
rm -r libmemcached-0.50*
rm -r memcached-
精彩评论