问题
I installed memcache via ssh, with:
$ pecl install memcache
And this was the output: https://pastee.org/w63sy
And added this line to etc/php.ini
:
extension=memcache.so
And when trying to initialize:
/* MEMCACHE */
$memcache = new Memcache();
$memcache->pconnect('localhost',11211);
I get:
Fatal error: Class 'Memcache' not found in /home/piscolab/public_html/website.com/includes/sql.php on line 25
What am I doing wrong?
I found this question but the problem was about his shared server. I am under a VPS.
Running: php -i | grep php.ini
:
[root@vps ~]# php -i | grep php.ini
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/memcache.so' - /usr/lib/php/modules/memcache.so: cannot open shared object file: No such file o
r directory in Unknown on line 0
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
[root@vps ~]#
Finding memcache.so (no output)
[root@vps ~]# find / -type f -name memcache*.so'
[root@vps ~]# find / -type f -name memcache*.so
[root@vps ~]#
回答1:
Given the output of the error message, it looks like you are missing the zlib
development libraries, or at least they are not in the usual location where it can be automatically found by configure.
Since you are on CentOS, try installing the libraries with this command:
yum install zlib-devel
This installs the zlib library which is required for memcache. Try re-running the pecl installer after installing the zlib libraries.
回答2:
it will probably help if you give some more info via phpinfo() or php_config, more specifically, does your install see the memcache libs and are your lib paths correct.
php-config
will tell you more, interesting here are the php ini path used and the lib paths php ini path will be displayed when you use --configure-options, suboption --with-config-file-path (/etc/php5/apache2 in my specific case) and the lib paths will be displayed with --extension-dir
e.g.
php-config --extension-dir
php-config --configure-options | grep -o 'with-config-file-path[^ ,.]*' | grep -o '[^=.]*$'
So to use my example my lib paths are set to
/usr/lib/php5/20090626+lfs and an
ls /usr/lib/php5/20090626+lfs/mem*
command for my system reveals:
/usr/lib/php5/20090626+lfs/memcached.so
and my php.ini file is located at /etc/php5/apache2/php.ini
the phpinfo() php function (just place in a file and view it) also reveals memcache as supported and loaded "memcached support enabled" (I specifically used memcached extension, not memcache)
mind you that your webserver might be configured to use a different php.ini path (and thus file) than your command line, so verify both. Also make sure you place the extension=memcache.so in the correct location, since many distros place it in /etc/php5/conf.d/memcache.ini might be there's some discrepancy there?
来源:https://stackoverflow.com/questions/10773524/fatal-error-class-memcache-not-found-installed-with-pecl