💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` $baseUrl = "http://192.168.7.233:9200/"; $client = new \GuzzleHttp\Client(['base_uri'=>$baseUrl]); $route = "/syslog-20200430/syslog/AXHIYvFxkH5UzwK97ZzM"; $route = "_count"; $route = "_search"; $route = "/syslog-20200430/syslog/_count"; $route = "/syslog-20200430/syslog/_search"; $route = "/_template"; // $route = urlencode($route); $body = [ 'headers'=> [ 'Content-Type' => 'application/json', ], 'json'=> [ 'query'=> [ 'match'=> [ '@timestamp'=> "2020-04-30T00:22:12.761Z" ] ] ], 'json'=> [ 'query'=> [ 'must'=> [ 'match'=> [ '@timestamp'=> "2020-04-30T00:22:12.761Z" ] ], 'filter'=> [ 'range'=> [ '@timestamp'=> "2020-04-30T00:22:12.761Z" ] ], ] ] ]; // $response = $client->request('GET', $route, $body); $route = "/apilog_".date('Ymd'); $body = [ 'settings' => [ 'number_of_shards' => 5, 'number_of_replicas' => 1 ], 'mappings' => [ '_source' => [ 'enabled' => true ], 'properties' => [ 'id' => [ 'type' => 'long' ], # 单次请求标识ID 'request_id' => [ 'type' => 'long', ], # api请求路由 eg:/a/b/c 'api' => [ 'type' => 'text', ], # 客户端调用方唯一标识ID, eg: #8asdasdasf242544 'partner_id' => [ 'type' => 'text', ], # 客户端调用方HOST 'client_host' => [ 'type' => 'ip', ], # 请求参数,应该是个querystring【类似 ?name=54skyer&age=18..】,会做搜索 'request_data' => [ 'type' => 'object', ], # 请求的时间,取程序当前时间,这里不确定存时间戳还是日期,不太清楚二者区别,但是该字段会作为搜索条件 'request_time' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss', ], # 日志记录的时间,不做搜索 'log_time' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss', 'index'=> false ], # 客户端请求到服务的连接耗时,单位秒,逻辑上会用 (request_time - 请求参数里的timestamp字段【客户端程序当前时间】),会做搜索条件 'connect_cost_time' => [ 'type' => 'short', ], # 服务端业务逻辑响应耗时,单位秒,逻辑上会用 (log_time - request_time),会做搜索条件 'service_cost_time' => [ 'type' => 'short', ], # 响应信息里的code 0正常 其他数字不正常, 会做搜索,用来排错 'code' => [ 'type' => 'long', ], # 响应信息里的msg 参数异常,业务逻辑异常,数据库连接异常等等各种无法正常响应请求的自定义信息, 会做搜索,用来排错 'msg' => [ 'type' => 'text', ], # 响应数据,可能是个json字符串或者xml字符串 'response_data' => [ 'type' => 'text', ], ], ] ]; $response = $client->request('PUT', $route, $body); $content = json_decode($response->getBody()->getContents(), true); return $content; ``` ***** $baseUrl = "http://192.168.7.233:9200/"; $client = new \GuzzleHttp\Client(['base_uri'=>$baseUrl]); // $route = "/syslog-20200430/syslog/AXHIYvFxkH5UzwK97ZzM"; // $route = "_count"; // $route = "_search"; // $route = "/syslog-20200430/syslog/_count"; // $route = "/syslog-20200430/syslog/_search"; // $route = "/_template"; // // $route = urlencode($route); // $body = [ // 'headers'=> [ // 'Content-Type' => 'application/json', // ], // 'json'=> [ // 'query'=> [ // 'match'=> [ // '@timestamp'=> "2020-04-30T00:22:12.761Z" // ] // ] // ], // 'json'=> [ // 'query'=> [ // 'must'=> [ // 'match'=> [ // '@timestamp'=> "2020-04-30T00:22:12.761Z" // ] // ], // 'filter'=> [ // 'range'=> [ // '@timestamp'=> "2020-04-30T00:22:12.761Z" // ] // ], // ] // ] // ]; // $response = $client->request('GET', $route, $body); $routeTemp = "/apilog_".date('Ymd')."/amazon/"; $response = $client->request('PUT', $route, $body); // $body = [ // 'settings' => [ // 'number_of_shards' => 5, // 'number_of_replicas' => 1 // ], // 'mappings' => [ // '_source' => [ // 'enabled' => true // ], // 'properties' => [ // 'id' => [ // 'type' => 'long' // ], // # 单次请求标识ID // 'request_id' => [ // 'type' => 'long', // ], // # api请求路由 eg:/a/b/c // 'api' => [ // 'type' => 'text', // ], // # 客户端调用方唯一标识ID, eg: #8asdasdasf242544 // 'partner_id' => [ // 'type' => 'keyword', // ], // # 客户端调用方HOST // 'client_host' => [ // 'type' => 'ip', // ], // # 请求参数,应该是个querystring【类似 ?name=54skyer&age=18..】,会做搜索 // 'request_data' => [ // 'type' => 'object', // ], // # 请求的时间,取程序当前时间,这里不确定存时间戳还是日期,不太清楚二者区别,但是该字段会作为搜索条件 // 'request_time' => [ // 'type' => 'date', // 'format' => 'yyyy-MM-dd HH:mm:ss', // ], // # 日志记录的时间,不做搜索 // 'log_time' => [ // 'type' => 'date', // 'format' => 'yyyy-MM-dd HH:mm:ss', // 'index'=> false // ], // # 客户端请求到服务的连接耗时,单位秒,逻辑上会用 (request_time - 请求参数里的timestamp字段【客户端程序当前时间】),会做搜索条件 // 'connect_cost_time' => [ // 'type' => 'short', // ], // # 服务端业务逻辑响应耗时,单位秒,逻辑上会用 (log_time - request_time),会做搜索条件 // 'service_cost_time' => [ // 'type' => 'short', // ], // # 响应信息里的code 0正常 其他数字不正常, 会做搜索,用来排错 // 'code' => [ // 'type' => 'long', // ], // # 响应信息里的msg 参数异常,业务逻辑异常,数据库连接异常等等各种无法正常响应请求的自定义信息, 会做搜索,用来排错 // 'msg' => [ // 'type' => 'text', // ], // # 响应数据,可能是个json字符串或者xml字符串 // 'response_data' => [ // 'type' => 'text', // ], // ], // ] // ]; // $response = $client->request('PUT', $route, $body); // $content = json_decode($response->getBody()->getContents(), true); // return $content; set_time_limit(18000); // phpinfo();die; $start = time(); // dd(\App\Model\MongoDb\Log::count([])); $batchArr = []; $platform = [ 'amazon', 'shopee', 'wish', 'ebay', 'aliexpress' ]; $route = [ 'orders', 'products', 'logistics', 'finance', 'inventory' ]; $random1 = [ "bfowmHI6NAn3q0CS", "OIY6dkAFeNRGimWg", "WqmLYryIafmb240t", "egBNXtXzPvnpVH1x", "pkC1bziiG6QGxSKr", ]; $random2 = [ "bfowmHI6NAn3q0CS", "OIY6dkAFeNRGimWg", "WqmLYryIafmb240t", "egBNXtXzPvnpVH1x", "pkC1bziiG6QGxSKr", ]; $currentTime = time(); for($i=105676; $i< 5000000; $i++){ $request_id = date('YmdHis').rand(1000,9999); dd((int) $request_id); $body = [ 'headers'=> [ 'Content-Type' => 'application/json', ], 'json'=> [ 'id' => (int) $request_id, # 单次请求标识ID 'request_id' =>(int) $request_id, # api请求路由 eg:/a/b/c "api"=> "/".$platform[rand(0,4)]."/".$route[rand(0,4)]."", # 客户端调用方唯一标识ID, eg: #8asdasdasf242544 'partner_id' => "sync_task", # 客户端调用方HOST 'client_host' => "192.168.30.100", # 请求参数,应该是个querystring【类似 ?name=54skyer&age=18..】,会做搜索 'request_data' => [ "platform"=> $platform[rand(0,4)], "route"=>$route[rand(0,4)], "access_token"=> "50000101510awsuehRDWSh1c02fe70ahAPCsS0eHdJmzEsXCky8tPDKok2iVt0" ], # 请求的时间,取程序当前时间,这里不确定存时间戳还是日期,不太清楚二者区别,但是该字段会作为搜索条件 'request_time' => date('Y-m-d H:i:s', $currentTime+(rand(-864000, 864000))), # 日志记录的时间,不做搜索 'log_time' => "2020-05-03 09:12:00", # 客户端请求到服务的连接耗时,单位秒,逻辑上会用 (request_time - 请求参数里的timestamp字段【客户端程序当前时间】),会做搜索条件 'connect_cost_time' => $i, # 服务端业务逻辑响应耗时,单位秒,逻辑上会用 (log_time - request_time),会做搜索条件 'service_cost_time' => $i+2, # 响应信息里的code 0正常 其他数字不正常, 会做搜索,用来排错 'code' => 0, # 响应信息里的msg 参数异常,业务逻辑异常,数据库连接异常等等各种无法正常响应请求的自定义信息, 会做搜索,用来排错 'msg' => "success", # 响应数据,可能是个json字符串或者xml字符串 'response_data' => '/rest/image/migrate?access_token=50000101510awsuehRDWSh1c02fe70ahAPCsS0eHdJmzEsXCky8tPDKok2iVt0&app_key=102187&partner_id='.$random1[rand(0,4)]."/".$random2[rand(0,4)].'&payload=<?xml version="1.0" encoding="UTF-8" ?> <Request> <Image> <Url><![CDATA[http://th-imgs.oss-cn-shenzhen.aliyuncs.com/ft/1/2/122149-8.jpg?x-oss-process=image/resize,l_1200/watermark,image_d2F0ZXJtYXJrL0xBNDMucG5n,t_100,g_nw&t=1588162428]]></Url> </Image> </Request>&sign_method=sha256&sign=A82ACC682ED2C60E5108B7BB7E6D5022792E6872496DA158E4F1BEB7AA823896&timestamp=1588162428505', ] ]; // if($i !=0 && $i%1000==0){ // $result = \App\Model\MongoDb\Log::insert($batchArr); // $batchArr = []; // var_export($result)."<br/>"; // } $response = $client->request('PUT', $routeTemp.$i, $body); // $content = json_decode($response->getBody()->getContents(), true); // return $content; } // $where = [ // ['logTime', ">", time()-86400*2], // ['logTime', "<", time()+86400*2], // // ['requestUrl', 'like', '%egBNXtXzPvnpVH1x/OIY6dkAFeNRGimWg%'] // ]; // $record = \App\Model\MongoDb\Log::paginate($where); // echo ("完成查询,耗时".(time()-$start)."<br/>"); // dd($record); dd("完成插入,耗时".(time()-$start)); /* define('USER_INFO', '中间件首页访问'); //行为类型,1登入,2退出,3增加,4修改,5查询,6删除,0其他 define('ACTION_TYPE', 5); return view('index.index');