PHP + Memcache wordpress Total Access count (non-plug-in) _ PHP Tutorial

Source: Internet
Author: User
PHP + Memcache: total wordpress access count (non-plug-ins ). I wrote a blog post and used PHP and Memcache to implement the website. For more information, see the following link: www.jb51.netarticle51825.htm. today, I used this function in wordpress and wrote a blog post before accessing the website, using PHP and Memcache to implement the website, see the following link: http://www.jb51.net/article/51825.htm
Today, we will use this function in wordpress and save the number of visits to the database.

MySQL statement

First, add the default number of visits to the parameter table

// Obtain all browsing times function get_all_visit_number () {$ mc = new Memcache (); // use wordpress's built-in wpdb class global $ wpdb; // parameter table $ table = "wp_options "; // connect to memcache $ mc-> connect ("127.0.0.1", 11211); // get browsing times $ visit_number = $ mc-> get ('Visit _ number '); // whether the Memcache contains the access times if (! $ Visit_number) {// Query Database $ querystr = "SELECT 'option _ value' FROM" when the database does not exist ". $ 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 the browsing times $ mc-> set ('Visit _ number', ++ $ visit_number ); // Obtain the number of browsing times $ visit_number = $ mc-> get ('Visit _ number'); // For every 100 visits, update to database if ($ visit_number % 100 = 0) {// use the wordpress built-in wpdb class $ data_array = array ('option _ value' => $ visit_number ); $ where_clause = array ('option _ name' => 'Visit _ number'); $ wpdb-> update ($ table, $ data_array, $ where_clause );} // close the memcache connection $ mc-> close (); return $ visit_number ;}

Login PHP and Memcache implementation site, the following link to view: http://www.jb51.net/article/51825.htm today to use this function in wordpress, and achieve the access...

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.