SAE Cloud Application Counter tool for access counting

Source: Internet
Author: User
SAE Cloud Application Counter tool for access counting

First, Introduction

Sina SAE has provided us with a fast-growing cloud application platform, some of which are very interesting to use.

Like the counter tool, we can use it to implement an access counter.

We can find it here.

The page displays the tool's constructors and invocation examples.


    classsaecounter {__construct ();//constructor that throws an exception if it fails. BOOL Create (string name, [int initial_value =0]);//Add a counter name with a default value of 0. The success returns True, and the failure returns false. BOOL Remove (string name);//Remove the counter named name. The success returns True, and the failure returns false. BOOL Exists (string name);//Determine if the counter name exists. There is a return of true, there is no return false. MixedList();//Gets all the counters for the app. The array returned successfully, and the failure returned false. Mixed length ();//successfully returned the total number of counters for the app, and failed to return false. Mixed get (string name);//Gets the value of the counter name. The value of the counter is returned successfully, and the failure returns false. BOOL Set (string name, int value);//Reset the counter name to value. The success returns True, and the failure returns false. Mixed Mget (Array(name1,name2,...));//Get multiple counter values simultaneously. The hash array was successfully returned with the counter named Index, and the failure returned false. Mixed GetAll ();//Gets the value of all counters for the app. Returns the same mget operation. Mixed incr (string name, [int vaule =1]);//To the counter name to do the addition operation, the default plus 1. The value of the counter is returned successfully, and the failure returns false. Mixed DECR (string name, [int vaule =1]);//subtraction of counter name, minus 1 by default. The value of the counter is returned successfully, and the failure returns false. }?>

Invoke Example


   
    try{        $c = new SaeCounter();    }catch(Exception$ex){        die($ex->getMessage());    }    $c->get('c1'); // 返回c1的值$c->set('c1', 100); // 返回true$c->incr('c1'); // 返回101$c->decr('c1'); // 返回100?>

Create a process

Start by creating a new counter, where you create a new counter variable.

Here we set a Request_counter variable, the initial value is initially set to 0.

Add the counter code to the portal file as follows:

//---------------添加计数器功能----------------add-time-15/09/06-pm--------try{        $cnew SaeCounter();  }  catch(Exception$ex){        die($ex->getMessage());   }    $c->get('request_counter');  // 获取值$c->incr('request_counter'// 计数器加1//--------------计数功能添加结束---------------------------------------------

This way we can visually see the latest access data, and of course we can combine our access log files to make it more perfect.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the SAE Cloud Application Counter tool to achieve the access count, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.