Write a pageview function with tp5, + 1 for each page refresh, the local test is normal, but put online for each refresh + N

use tp5 to write a pageview function, each page refresh on + 1, offline local test is normal, put online, using the server"s browser test is also + 1, offline access online is changed to each refresh + 4, with static variable test results executed only once, exclusion code Bug, where is the problem?

attach code:

/**
     * 
     * +1
     */
    public function detail($id="",$browse=true,$sql=false)
    {
        if (empty($id)) goto end;
        $data = $this->alias("a","left")
        ->field("a.id,a.tid,a.title,a.keyword,a.introduce,a.content,a.img,a.addtime,a.browse,u.name user_name,t.name type_name")
        ->join("tags t","t.id=a.tid","left")
        ->join("user u","u.id=a.uid","left")
        ->where(array("a.id"=>$id,"a.status"=>2)) 
        ->find();
        // dp($this->getLastSql());
        if (true == $sql) return $this->getLastSql();
        end:
        if (empty($data)) return null;
        //+1
        if (true == $browse) $this->where("id",$data["id"])->setInc("browse");

        $data = $data->toArray();
        $data["user_name"] ? : $data["user_name"] = "admin";
        return $this->cotm($data);
    }

this is the only operation in which the code for browsing + 1 is written

if (true = = $browse) $this- > where ("id",$data [" id"])-> setInc ("browse");

found the reason. I looked at the log and found that the program was executed four times
but why was it executed four times?


have you seen the server log and are you sure there are no other access requests during the test period?


maybe your server has a bit of a card, refreshing the interface once and requesting multiple times, you can set a time interval.


first of all, don't say bug, I don't know, I don't bother to look at the code. On the other hand, the number of page views is not increased by refresh. you can consider writing an interface to add one, js to judge, and request the interface after the page is loaded.


do a good job of js anti-shaking or throttling

Menu