views:

349

answers:

2

Hi,

I'm using Memcached PHP library (based on libmemcached) and I'm wondering how can I change predefined constants in PHP. I'd like to use key distribution based on ketama.

Memcached is compiled as a PHP extension.

Thank you.

A: 

I don't think you can. The memcached settings are decided when the php extension is compiled I believe. If you really need to use different settings for memcached, compile a number of different memcached extension files (each with a different configuration), give each a suitable name, and then use the dl function (http://uk3.php.net/dl), to load the correct one at runtime.

(This does of course assume you have control over the server.)

Kazar
Documentation says: Memcached::OPT_BINARY_PROTOCOL Enable the use of the binary protocol. Please note that you cannot toggle this option on an open connection. Type: boolean, default: FALSE.Which would indicate that you can change this setting on an open connection, so there must be a away to change the settings once the PHP is already executing the script.
Matic
+2  A: 

use setOption:

$this->_Memcache =& new Memcached();
$this->_Memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);
$this->_Memcache->setOption(Memcached::OPT_NO_BLOCK, true);
$this->_Memcache->setOption(Memcached::OPT_TCP_NODELAY, true);
$this->_Memcache->setOption(Memcached::OPT_BUFFER_WRITES, true);
$this->_Memcache->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT,3);
$this->_Memcache->setOption(Memcached::OPT_HASH,Memcached::HASH_CRC);

etc... etc...

Jason