Example of memcache usage in Yii framework, Yiimemcache
The examples in this paper describe the Memcache usage in Yii framework. Share to everyone for your reference. The specific analysis is as follows:
In the current company is the framework of yii, contact with more things, can learn more things, in the previous company did not contact Memcache, just heard, but never really used. Now finally have the opportunity to use, just take my project as an example!
I do the project is a mobile ranking, but the leaderboard every 15 minutes refreshed Ah, the leaderboard has a top three, perhaps the first 15 minutes of the three people are the top three, perhaps the next 15 minutes is the first three people, product requirements, as long as the top three are to send prizes, thinking for a long time, The final decision is to use Memcache to store the top three information for every 15 minutes. The code is as follows:
Copy the Code Code as follows: Public function GetChargeRank3 ()
{
$startime = ' 2014-04-10 00:00:00 ';
$endtime = ' 2014-04-30 23:59:59 ';
$sql = "SELECT Top 3 user_id, sum (point) as total from table where state=5 and cp_id>=11 and cp_id<=19 and Pay_time & Gt;= ' $startime ' and pay_time<= ' $endtime '
Group BY user_id ORDER by total DESC ";
$result = Yii::app ()->controller>createcommand ($sql)->queryall ();
$cache = Yii::app ()->cache->get ($key);
if ($cache!=false)
{
foreach ($result as $key = $val)
{
Here for the inside gift code, inconvenient to disclose
}
}
Yii::app ()->cache->set ($key, $result, Strtotime ($endtime));//write the first three names to the cache
}
It is hoped that this article is helpful to the PHP program design based on YII framework.
http://www.bkjia.com/PHPjc/920972.html www.bkjia.com true http://www.bkjia.com/PHPjc/920972.html techarticle The example of memcache usages in Yii framework Yiimemcache the Memcache usage in Yii framework. Share to everyone for your reference. The specific analysis is as follows: At present the company uses the y ...