thinkphp implementation of Memcache distributed cache function _php instance

Source: Internet
Author: User
Tags php template smarty template
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.