Page MenuHomePhabricator

memcached class conflicts with PHP's memcached extension
Closed, ResolvedPublic

Description

Author: hjkim

Description:
I upgraded wikimedia from 1.15 to 1.16-svn and tested brand new vector skin. it looks well/

in LocalSettings.php, I assigned cache type to CACHE_MEMCACHED. and after that PHP does not operates.
In apache log, the message is


PHP Warning: Memcached::__construct() expects parameter 1 to be string, array given in /usr/share/mediawiki/includes/ObjectCache.php on line 63, referer: <url>

PHP Fatal error: Call to a member function set_servers() on a non-object in /usr/share/mediawiki/includes/ObjectCache.php on line 64, referer: <url>

memcached version 1.4.2, and PHP-memcached was built into PHP as static library. The PHP-memcached version is 1.0, which was built against libmemcached 0.3.0. PHP version is 5.2.11.


Version: 1.16.x
Severity: major
OS: Linux
Platform: PC
URL: http://aerospace.ulsan.ac.kr/cim/wiki

Details

Reference
bz21403

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:49 PM
bzimport set Reference to bz21403.
bzimport added a subscriber: Unknown Object (MLST).

It seems that there is a conflict between PHP's memcached extension (http://www.php.net/manual/en/book.memcached.php) and our memcached class (includes/memcached-client.php).

hjkim wrote:

(In reply to comment #1)

Are you sure you configured stuff correctly? See
http://www.mediawiki.org/wiki/Memcached#Setup

Yes, I configured memcached daemon as a background service. My server Linux distro is Fedora Core 11(FC11),
At First I thought that the version of memcached and PHP-memcached is old, so I downloaded recent version source tarballs from developers website. and I compiled and installed to my server. But still it does not work.

In LocalSettings.php, all settings about memcacehd is correct, I thought. But maybe still error? :) I copied my LocalSettings.php's memcached section to it


Shared memory settings

$wgMainCacheType = CACHE_MEMCACHED;
$wgParserCacheType = CACHE_MEMCACHED; # optional
$wgMessageCacheType = CACHE_MEMCACHED; # optional
$wgMemCachedServers = array("localhost:11211");
$wgUseFileCache = true;
$wgSessionsInMemcached = true; # optional
$wgMemCachedPersistent = true;
$wgFileCacheDirectory = '/tmp/wikicache';
$wgCacheDirectory = '/tmp/wikicache';

$wgUseMemCached = true;

Still error in my configuration? If so, tell me about some tips and how-tos to me, please.

Thanks Roan.
I use file cache also. and I turned off MEMCACHED support by usgin CACHE_ANYTHING.

hjkim wrote:

(In reply to comment #2)

It seems that there is a conflict between PHP's memcached extension
(http://www.php.net/manual/en/book.memcached.php) and our memcached class
(includes/memcached-client.php).

Yes, I saw PHP manual about memcached extensions, and the memcached:__construct() accepts a single string variable. But MediaWiki's Cache routine is not.

Line from 53 to 67 in includes/ObjectCache.php


53 if ( $type == CACHE_MEMCACHED ) {
54 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
55 if ( !class_exists( 'MemCachedClientforWiki' ) ) {
56 class MemCachedClientforWiki extends memcached {
57 function _debugprint( $text ) {
58 wfDebug( "memcached: $text" );
59 }
60 }
61 }
62 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
63 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
64 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
65 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
66 }

67 $cache =& $wgCaches[CACHE_MEMCACHED];

At line 62-63, the codes is contructing memcache persistence connection. But the argument is array, not string. I think that if the argument is not string, PHP can not parse codes, even if all array's elements are string.

Do you have any solution to it? I edited some codes for fixing, but still not work. My PHP is poor... :(..

Thanks for reading and review my bug, Alexandre.

hjkim wrote:

some edits to avoid conflicting PHP-memcached extension

if PHP-memcached extension installed and activated, MediaWiki's the class memcached in memcached-client.php is conflicts with PHP-memcached extension.

It's because memcache-dclient class use same name class, and does not overrides PHP-memcached class. So, I renamed class name to mwMemcached.

It works well. And at top of ObjectCache.php, just add this line

require_once('ObjectCache.php');

and edit ObjectCache.php with other patch that I attached.

I hope this will help~ :)

Attached:

hjkim wrote:

including patched memcached-client.php patch

After patching memcached-client.php, patch ObjectCache.php to use edited memcached-client class 'mwMemcached'.

It's so simple, and works well with memcached daemon.

I hope this will help~ :)

Attached:

hjkim wrote:

oops! in comment #5 with memcached-client.php patch, there's mistake.

correct mistake.

require_once('ObjectCache.php');

-> require_once('memcached-client.php');

please see and review my patch.
I think it doesn't have any license problem. isn't it?