Server One variable multiple users can be modified at the same time, how to implement

Source: Internet
Author: User
Server One variable multiple users can be modified at the same time, how to implement?
For example: I set the variable $ A,
Multiple members, called $ A, are the same object, not separate. But it cannot be implemented with a database.
$a = 100;

When Zhang San, visit $ A and change $ A to 5;
At this point, John Doe access $ A, see $ A $5, John Doe change $ A to 50,

Multiple users can modify $ A and more can be seen. Similar to shared variables.

How is it implemented?

------Solution--------------------
Public variable class PHP code based on Memcache
Class Tshare {  private static $_instance;  Private $memcache;  Private Function __construct () {    $this->memcache = new Memcache;    $this->memcache->connect (' 127.0.0.1 ', 11211) or Die ("Could not Connect");  }  public static function getinstance () {    if (empty (self::$_instance)) self::$_instance = new self ();    return self::$_instance;  }  function __set ($name, $val) {    $this->memcache->set ($name, $val, false, +);  }  function __get ($name) {    return $this->memcache->get ($name);  
  • 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.