How can multiple users modify a variable on the server at the same time? For example, when I set the variable $ a and multiple members call $ a, they all belong to the same object instead of being independent. But it cannot be implemented using a database. $ A = 100; when Michael Jacob accesses $ a, Change $ a to 5. then, Li Si visits $ a and sees $ a as 5. Li Si changes $ a to 50, you can modify $ a for multiple users. Similar to shared variables. How to implement it ?, Based on the mem server, multiple users can modify a variable at the same time. how can this problem be achieved?
For example, I set the variable $,
When multiple members call $ a, they all belong to the same object, rather than being independent. But it cannot be implemented using a database.
$ A = 100;
When Michael Jacob accesses $ a, Change $ a to 5;
At this time, Li Si visited $ a and saw that $ a is 5. Li Si changed $ a to 50,
You can modify $ a for multiple users. Similar to shared variables.
How to implement it?
------ Solution --------------------
Memcache-based public Variable class
PHP code
Class TShare {private static $ _ Instance; private $ memcache; private function _ construct () {$ this-> memcache = new Memcache; $ this-> memcache-> connect ('2017. 0.0.1 ', 11211) or die ("cocould 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, 1000);} function _ get ($ name) {return $ this-> memcache-> get ($ name );}}