tongshanglei 1 년 전
부모
커밋
e095326f04
1개의 변경된 파일37개의 추가작업 그리고 34개의 파일을 삭제
  1. 37 34
      catch/api/controller/Api.php

+ 37 - 34
catch/api/controller/Api.php

@@ -300,43 +300,46 @@ class Api extends CatchController
 
     }
     public function asset_redis(){
-        $redis=Cache::store('redis')->handler();
-        $hashKey='station_access_last_data';
-        $beforeKey='station_access_before_data';
-        $list=$redis->hgetall($hashKey);
-        foreach($list as $key=>$val){
-            $report_data = json_decode($val, true);
-            if ( (time() - $data["time"] ) > 10 ) {
-                $before_data=json_decode($redis->hGet($beforeKey,$key),true);
-                //存在反向数据 并且连续搜到单边数据5次
-                if($before_data){
-                                //开始推送数据;
-                    $send_data=[
-                        "mac"=>$report_data['mac'],
-                        "label"=>$report_data['label'],
-                        'time'=>$report_data['time'],
-                    ];
-
-                    if($report_data['ant']>$before_data['ant']){
-                        //1->2 内到外 出
-                        $send_data['dirt']=2;
-                    }else{
-                        //2>1  外到内 进
-                        $send_data['dirt']=1;
+        while(true){
+            $redis=Cache::store('redis')->handler();
+            $hashKey='station_access_last_data';
+            $beforeKey='station_access_before_data';
+            $list=$redis->hgetall($hashKey);
+            foreach($list as $key=>$val){
+                $report_data = json_decode($val, true);
+                if ( (time() - $report_data["time"] ) > 10 ) {
+                    $before_data=json_decode($redis->hGet($beforeKey,$key),true);
+                    //存在反向数据 并且连续搜到单边数据5次
+                    if($before_data){
+                        //开始推送数据;
+                        $send_data=[
+                            "mac"=>$report_data['mac'],
+                            "label"=>$report_data['label'],
+                            'time'=>$report_data['time'],
+                        ];
+    
+                        if($report_data['ant']>$before_data['ant']){
+                            //1->2 内到外 出
+                            $send_data['dirt']=2;
+                        }else{
+                            //2>1  外到内 进
+                            $send_data['dirt']=1;
+                        }
+                        var_dump($send_data);
+                        //推送数据
+                        $url="http://localhost:8115/api/assetReport";
+                        $postFields = http_build_query($send_data);
+                        $url_res= curl_http_post($postFields,$url,false);
+                        echo 'assetReport res'.PHP_EOL;
+                        var_dump($url_res);
+                        //推送完清除数据
+                        $redis->hDel($hashKey,$key);
+                        $redis->hDel($beforeKey,$key);
+                                
                     }
-                    var_dump($send_data);
-                    //推送数据
-                    $url="http://localhost:8115/api/assetReport";
-                    $postFields = http_build_query($send_data);
-                    $url_res= curl_http_post($postFields,$url,false);
-                    echo 'assetReport res'.PHP_EOL;
-                    var_dump($url_res);
-                    //推送完清除数据
-                    $redis->hDel($hashKey,$key);
-                    $redis->hDel($beforeKey,$key);
-                            
                 }
             }
+           sleep(1);
         }
     }
     /**