PHP uses memcache caching technology to introduce _php tutorials in a nutshell

Source: Internet
Author: User
A PHP with Memcache cache technology to improve the responsiveness of friends who need to refer to the reference.

Connecting to a 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);


Example 1

The code is as follows Copy Code

!--? php
//connection
$mem = new Memcache;
$mem->connect ("127.0.0.1″, 11211) or Die (" Could not Connect ");
//Display version
$version = $mem->getversion ();
echo "Memcached Server version:". $version. "
";
//Save Data
$mem->set (' key1′, ' This is first value ', 0);
$val = $mem->get (' key1′);
echo "Get key1 value:". $val. "
";
//Replace data
$mem->replace (' key1′, ' This is replace value ', 0,);
$val = $mem->get (' key1′);
echo "Get key1 value:". $val. "
";
//save array
$arr = Array (' AAA ', ' BBB ', ' CCC ', ' ddd ');
$mem->set (' key2′, $arr, 0, 60);
$val 2 = $mem->get (' key2′);
echo "Get Key2 value:";
Print_r ($val 2);
echo "
";
Delete Data
$mem->delete (' key1′);
$val = $mem->get (' key1′);
echo "Get key1 value:". $val. "
";
//Clear All data
$mem->flush ();
$val 2 = $mem->get (' key2′);
echo "Get Key2 value:";
Print_r ($val 2);
echo "
";
Close connection
$mem->close ();
?

The Memcache function library is in pecl (PHP Extension Community Library), the main role is to build a large amount of memory data temporary storage area

, in the distribution of the role embodied in the very obvious, network marketing training is not recommended to use.

Memcache::add-Adds a value that returns false if it already exists
Memcache::addserver-Add a server address that is available for use
Memcache::close-Closes a Memcache object
Memcache::connect-Create a Memcache object
Memcache_debug-Control the debugging Function! [4 F8 C2 E, X
Memcache::d ecrement-Subtract from the value in a saved key
Memcache::d elete-delete a key value
Memcache::flush-Clears all cached data
Memcache::get-Gets a key value
Memcache::getextendedstats-Gets the running system statistics for all processes in the process pool
Memcache::getserverstatus-Get parameters to run the server
Memcache::getstats-Returns some run statistics for the server
Memcache::getversion-Returns the version information of the running Memcache
Memcache::increment-Adds an addition to the value in a saved key
Memcache::p Connect-Create a Memcache persistent connection object
Memcache::replace-Overwrite an existing key
Memcache::set-Adds a value that, if already present, overwrite
Memcache::setcompressthreshold-compression of data larger than a certain size
Memcache::setserverparams-Modifying the server's parameters at run time


http://www.bkjia.com/PHPjc/444628.html www.bkjia.com true http://www.bkjia.com/PHPjc/444628.html techarticle a PHP with Memcache cache technology to improve the responsiveness of friends who need to refer to the reference. Connect the database code as follows to copy code $memcache _obj = Memcache_connect (localhost, 11211 ...

  • 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.