For more information about how to use memcache cache to accelerate PHP response, see.
Connect to database
| The Code is as follows: |
Copy code |
$ Memcache_obj = memcache_connect ("localhost", 11211 ); Memcache_add ($ memcache_obj, 'var _ key', 'test variable', false, 30 ); $ Memcache_obj-> add ('var _ key', 'test variable', false, 30 ); |
Instance 1
| The Code is as follows: |
Copy code |
<? Php // Connection $ Mem = new Memcache; $ Mem-> connect ("127.0.0.1", 11211) or die ("cocould not connect "); // Display version $ Version = $ mem-> getVersion (); Echo "Memcached Server version:". $ version. "<br> "; // Save data $ Mem-> set ('key1', 'this is first value', 0, 60 ); $ Val = $ mem-> get ('key1 ′); Echo "Get key1 value:". $ val. "<br> "; // Replace Data $ Mem-> replace ('key1', 'this is replace value', 0, 60 ); $ Val = $ mem-> get ('key1 ′); Echo "Get key1 value:". $ val. "<br> "; // Save the Array $ Arr = array ('aaa', 'bbb ', 'ccc', 'ddd '); $ Mem-> set ('key2', $ arr, 0, 60 ); $ Val2 = $ mem-> get ('key2 ′); Echo "Get key2 value:"; Print_r ($ val2 ); Echo "<br> "; // Delete data $ Mem-> delete ('key1 ′); $ Val = $ mem-> get ('key1 ′); Echo "Get key1 value:". $ val. "<br> "; // Clear all data $ Mem-> flush (); $ Val2 = $ mem-> get ('key2 ′); Echo "Get key2 value:"; Print_r ($ val2 ); Echo "<br> "; // Close the connection $ Mem-> close (); ?> |
The Memcache function Library is used in the PECL (PHP Extension Community Library) to build a temporary storage area for large memory data volumes.
In distributed mode, network marketing training is not recommended.
Memcache: add-add a value. if it already exists, false is returned.
Memcache: addServer-add an available server address
Memcache: close-close a Memcache object
Memcache: connect-create a Memcache object
Memcache_debug-control debugging function! [4 F8 C2 e, X
Memcache: decrement-deletes the value of a saved key.
Memcache: delete-delete a key value
Memcache: flush-Clear All cached data
Memcache: get-get a key value
Memcache: getExtendedStats-obtains the running system statistics of all processes in the process pool.
Memcache: getServerStatus-get the parameters of the running server
Memcache: getStats-return some running statistics of the server
Memcache: getVersion-returns the version information of the running Memcache.
Memcache: increment-adds the value of a saved key.
Memcache: pconnect-creates a persistent connection object for Memcache.
Memcache: replace-overwrite an existing key
Memcache: set-Add a value. if it already exists, overwrite it.
Memcache: setCompressThreshold-compresses data larger than a certain size
Memcache: setServerParams-Modify server parameters at runtime