PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 13, 2022

[FIXED] What is Memcached::isPristine() used for in PHP?

 November 13, 2022     memcached, php     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing