This paper describes the thinkphp implementation of the Memcache distributed cache function. Share to everyone for your reference, as follows:
Two days in the study of the Memcache distributed cache problem, it was found that thinkphp does not support the distributed cache function, which can be seen from the official CacheMemcache.class.php file:
if (empty ($options)) { $options = array ( ' host ' = = ' 127.0.0.1 ', ' port ' = = 11211, ' timeout ' = > False, ' persistent ' = False );} $func = $options [' Persistent ']? ' Pconnect ': ' Connect '; $this->expire = Isset ($options [' expire '])? $options [' Expire ']:c (' data_cache_time '); $this- >handler = new Memcache; $this->connected = $options [' timeout '] = = = False? $this->handler-> $func ($options [' Host '], $options [' Port ']: $this->handler-> $func ($options [' Host '], $options [' Port '], $options [' timeout ']);
But it doesn't matter, just a little change, that
if (empty ($options)) { $options = array ( ' timeout ' = = false, ' persistent ' = = False, ' Servers ' =>array ( array (' ip ' = = ' 127.0.0.1 ', ' Port ' =>11211), array (' ip ' = = ' 127.0.0.1 ', ' port ' = >11212), array (' ip ' = = ' 202.116.32.4 ', ' Port ' =>11211),) ;} The distributed processing function $func= "Addserver"; $this->expire = Isset ($options [' expire '])? $options [' Expire ']:c (' data_cache_time '); $this->handler = new Memcache;if ($options [' timeout ']===false) { foreach ($options [' Servers '] as $server) { $this->handler-> $func ($server [' IP '], $server [' Port ']);} }
Idle to Nothing, so on this machine started the two Memcache server, handy to write a simple monitoring code (interval time automatically refresh once), to test. If you find that the server is not functioning properly, use Phpmailer to automatically send an email to the admin mailbox. The test results show that both memcache servers are working properly, while another false server is of course unable to connect. Haha, it's simple enough.
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.