Created
April 9, 2015 18:51
-
-
Save brianlmoon/c4c61aaa77a259a9860d to your computer and use it in GitHub Desktop.
Quickest, safe way to add servers using pecl-memcached and persistent connections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Let's assume this is coming from a config file somewhere | |
// that we can trust to not have duplicate servers in the list. | |
$servers = array( | |
array("host" => 'localhost', "port" => 11211, "weight" => 10), | |
array("host" => 'localhost', "port" => 11212, "weight" => 20) | |
); | |
$mc = new Memcached("test"); | |
/** | |
* We simply check if this is a newly create object. If it is, we add the | |
* servers. The down side of this is if you want to remove connections to | |
* servers due to the server list changing, you will need to restart all | |
* your PHP workers. | |
*/ | |
if($mc->isPristine()){ | |
$mc->addServers($servers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment