Php+memcache to achieve total number of WordPress access statistics (non-plug-in) _php instance

Source: Internet
Author: User
Tags php and

Previously wrote a blog post, using PHP and Memcache to implement the site, the following links to view: http://www.jb51.net/article/51825.htm
Today the feature is used in WordPress, and the implementation of the number of visits saved to the database.

MySQL statement

First, in the parameter table, add the default data for the number of accesses

Get all browse times function Get_all_visit_number () {$MC = new Memcache ();
 
 Use WordPress with wpdb class global $wpdb;
 
 Parameter table $table = "Wp_options";
 
 Connection Memcache $MC->connect ("127.0.0.1", 11211);
 
 Get browse times $visit _number = $MC->get (' Visit_number '); Memcache if (! $visit _number) {//does not exist, query database $querystr = ' select ' Option_value ' from '. $table. "
 WHERE ' option_name ' = ' visit_number ';
 
 $results = $wpdb->get_results ($QUERYSTR);
 Assign the value stored in the database to the memcache variable $visit _number = Intval ($results [0]->option_value);
 
 /set Browse times $MC->set (' visit_number ', + + $visit _number);
 

 Get browse times $visit _number = $MC->get (' Visit_number '); 100 visits per visit, updated to database if ($visit _number% 100 = 0) {//Use WordPress self-with wpdb class $data _array = Array (' Option_value ' =>
 
 $visit _number);
 
 $where _clause = Array (' option_name ' => ' visit_number ');
 $wpdb->update ($table, $data _array, $where _clause);
 
 }//Close memcache connection $MC->close (); Return $visit_number;

 }

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.