Issue
I've stumbled across Memcached::isPristine() while reading the docs regarding Memcached but got no idea what is it for.
I could notice it's linked to persistent connections but the documentation lacks those example use cases that are usually present in other pages.
Solution
I will explain it with an example
$m1 = new MemCached('test');
$m1->addServer('127.0.0.1', 11211);
$m2 = new MemCached('test');
$m2->addServer('127.0.0.1', 11211);
var_dump($m2->getServerList());
Output:
array(2) {
  [0]=>
  array(2) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["port"]=>
    int(11211)
  }
  [1]=>
  array(2) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["port"]=>
    int(11211)
  }
}
With isPristine
$m1 = new MemCached('test');
$m1->addServer('127.0.0.1', 11211);
$m2 = new MemCached('test');
if($m2->isPristine()) $m2->addServer('127.0.0.1', 11211);
var_dump($m2->getServerList());
Output:
array(1) {
  [0]=>
  array(2) {
    ["host"]=>
    string(9) "127.0.0.1"
    ["port"]=>
    int(11211)
  }
}
                        
                        Answered By - Nikolas Meyer Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.