PHP Opcode cache ANDMemcache cache usage guide PHP lifecycle requests --- & gt ;. php --- & gt; dictionary scanning --- & gt; parsing --- & gt; create Opcode --- & gt; process Opcode --- & gt; response even if the PHP script Opcode cache AND Memcache cache use guide
PHP lifecycle request --->. php ---> Dictionary scanning ---> parsing ---> creating Opcode ---> processing Opcode ---> The Zend Engine must re-create the Opcode of the file even if the content of the PHP script has not changed. opcode cache improves PHP performance ---> cache ---> read cached Opcode ---> process Opcode ---> response
Request --->. php
---> No cache ---> Dictionary scan ---> resolution ---> create Opcode ---> process Opcode ---> respond to Opcode cache tool APC for details, refer to APC cache in PHP (learn to sort out) for details about XCache, refer to PHP XCache cache using eACCelerator memory cache Memcache introduction the Memcache function Library is used in the PECL (PHP Extension Community Library) to build a temporary storage area for large-capacity memory data.
Memcache also provides processing for communication conversations (session_handler.
For more information about the Memcache module, visit the http://www.danga.com/memcached.
For more information about installing Memcache, see installing and using Memcache Functions under http://blog.csdn.net/initphp/article/details/8039917 liunx:
Reference http://www.php.net/manual/zh/function.Memcache-add.php 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 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 |
1. add a server to the object. (Note: If the addServer is not connected to the server, true is returned if the memcache process is not started)
// Parameter // @ param string $ host server domain name or IP address // @ param int $ port number, default value: 11211 // @ param bool $ persistent whether to use a common link, the default value is TURE // @ param int $ weight, which is the proportion of multiple server settings. // @ param int $ timeout indicates the number of seconds after the server fails to be connected. think twice when you change the default value of 1, the connection may be slow due to the loss of all cache advantages. // @ param int $ retry_interval the retry frequency when the server connection fails. the default value is 15 seconds, if it is set to-1, Automatic Retry is disabled. When dynamically via dl () is loaded in the extension, the parameter will be invalid regardless of this parameter or the constant connection setting parameter. Each failed server has its own life cycle before it expires. when a backend request is selected, it is skipped and does not serve the request. An expired connection will reconnect successfully or be marked as a failed connection and wait for the next retry. This effect means that the retry connection of each web server sub-process when serving the page is related to their own retry frequency. // @ Param bool $ status controls whether the server is marked as online, if this parameter is set to FALSE and retry_interval is set to-1, the connection failure server can be put into a server pool that does not respond to the request. requests to this server will fail, accept the failed server setting. the default parameter is TRUE, indicating that the server can be defined as online. // @ Param callback $ failure_callback: the callback function fails. The two parameters of the function are hostname and portbool Memcache: addServer (string $ host [, int $ port [, bool $ persistent [, int $ weight [, int $ timeout [, int $ retry_interval [, bool $ status [, callback $ failure_callback])
2. connect to the memcache server
// Parameter // @ param string $ host server domain name or ip // @ param int $ post server tcp port number, the default value is 11211 // @ param $ timeout, indicating the expiration time of the memcache process. you must think twice when modifying its default value 1, to avoid losing all memcache Cache advantages, resulting in slow connection // @ return boolbool Memcache: connect (string $ host [, int $ port [, int $ timeout])
Case:
/* procedural API */$memcache_obj = memcache_connect(‘memcache_host‘, 11211);/* OO API */$memcache = new Memcache;$memcache->connect(‘memcache_host‘, 11211);
3. connect to the server as usual
bool Memcache::pconnect ( string $host [, int $port [, int $timeout ]] )
4. close the object (does not work for persistent connections)
bool Memcache::close ( void )
Case:
/* procedural API */$memcache_obj = memcache_connect(‘memcache_host‘, 11211);/* do something here .. */memcache_close($memcache_obj);/* OO API */$memcache_obj = new Memcache;$memcache_obj->connect(‘memcache_host‘, 11211);/* do something here .. */$memcache_obj->close();
5. add a value. if the value already exists, false is returned.
// Parameter // @ param string $ key the key of the cached data cannot exceed 250 characters. // @ param mixed $ var value. The integer type is directly stored, other types will be serialized for storage. The maximum value is 1 M // @ param int $ flag whether zlib is used for compression. when flag = MEMCACHE_COMPRESSED, zlib is not used for compression when the data size is small, only when the data size reaches a certain value can the data be compressed // @ param int $ expire expiration time. 0 indicates that the data never expires. you can use the unix time truncation format or the number of seconds from the current time, if it is set to seconds, it cannot be greater than 2592000 (30 days) // @ return returns TRUE if return succeeds, and FALSE if return Fails. if this key already exists, memcache:; add () behavior similar to memcache: set bool Memcache: add (string $ key, mixed $ var [, int $ flag [, int $ expire])
Case:
$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);
6. overwrite an existing key
// Parameter // @ param string $ key the key of the cached data // @ param mixed $ var value. The integer type is directly stored, and other types are serialized for storage, the maximum value is 1 M // @ param int $ flag whether zlib is used for compression. when the flag is MEMCACHE_COMPRESSED, zlib is not used for compression when the data is small, zlib compression is performed on data only when the data size reaches a certain value. (The minimum value for compression without specific test data) // @ param int $ expire Expiration Time, 0 is never expired, you can use the unix timestamp format or the number of seconds from the current time. The value cannot be greater than 2592000 (30 days) bool Memcache: replace (string $ key, mixed $ var [, int $ flag [, int $ expire])
Case:
$memcache_obj = memcache_connect("localhost", 11211);/* procedural API */memcache_replace($memcache_obj, "test_key", "some variable", FALSE, 30);/* OO API */$memcache_obj->replace("test_key", "some variable", FALSE, 30);
7. add a value. if it already exists, overwrite it.
// Parameter // @ param string $ key: the key to cache data, its length cannot exceed 250 characters // @ param mixed $ var // @ param int $ flag // @ param int $ expirebool Memcache: set (string $ key, mixed $ var [, int $ flag [, int $ expire])
Case:
$memcache_obj = memcache_connect("localhost", 11211);/*set value of item with key ‘var_key‘using 0 as flag value, compression is not usedexpire time is 30 second*/memcache_set($memcache_obj, ‘var_key‘, ‘some variable‘, 0, 30);echo memcache_get($memcache_obj, ‘var_key‘);