作者 赵彬吉

update

@@ -146,64 +146,68 @@ class WebTraffic extends Command @@ -146,64 +146,68 @@ class WebTraffic extends Command
146 */ 146 */
147 public function handle() 147 public function handle()
148 { 148 {
149 - $type = $this->argument('type'); 149 + try {
  150 + $type = $this->argument('type');
150 151
151 - $this->sleep($type); 152 + $this->sleep($type);
152 153
153 - $page = 1;  
154 - while (true){  
155 - $project_list = $this->getProjectList($type, $page);  
156 - if(!$project_list){  
157 - break;  
158 - }  
159 - $need_project = [];  
160 - foreach ($project_list as $project) {  
161 - //随机引流间隔  
162 - $res_sjjg = $this->get_rand($this->sjjg);  
163 - if ($res_sjjg == 1) {  
164 - continue; 154 + $page = 1;
  155 + while (true){
  156 + $project_list = $this->getProjectList($type, $page);
  157 + if(!$project_list){
  158 + break;
165 } 159 }
  160 + $need_project = [];
  161 + foreach ($project_list as $project) {
  162 + //随机引流间隔
  163 + $res_sjjg = $this->get_rand($this->sjjg);
  164 + if ($res_sjjg == 1) {
  165 + continue;
  166 + }
166 167
167 - $project_urls = $this->getProductUrls($project['project_id']);  
168 - $project_urls['home'] = $project['domain'];  
169 - //随机访问页面  
170 - $project['visit_urls'] = $this->getVisitUrls($project_urls);  
171 - //随机客户端  
172 - $project['device_port'] = $this->get_rand($this->yddzb);  
173 - $project['user_agent'] = $project['device_port'] == 1 ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua); 168 + $project_urls = $this->getProductUrls($project['project_id']);
  169 + $project_urls['home'] = $project['domain'];
  170 + //随机访问页面
  171 + $project['visit_urls'] = $this->getVisitUrls($project_urls);
  172 + //随机客户端
  173 + $project['device_port'] = $this->get_rand($this->yddzb);
  174 + $project['user_agent'] = $project['device_port'] == 1 ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
174 175
175 - $need_project[] = $project;  
176 - }  
177 - //随机访问ip  
178 - $ips = $this->getIpAreas(count($need_project));  
179 - //最多10层深度  
180 - $client = new Client(['verify' => false]);  
181 - for ($j = 0; $j < 10; $j++) { 176 + $need_project[] = $project;
  177 + }
  178 + //随机访问ip
  179 + $ips = $this->getIpAreas(count($need_project));
  180 + //最多10层深度
  181 + $client = new Client(['verify' => false]);
182 for ($j = 0; $j < 10; $j++) { 182 for ($j = 0; $j < 10; $j++) {
183 - //并发请求  
184 - $promises = [];  
185 - foreach ($need_project as $project_key => $project) {  
186 - if (empty($project['visit_urls'][$j])) {  
187 - continue; 183 + for ($j = 0; $j < 10; $j++) {
  184 + //并发请求
  185 + $promises = [];
  186 + foreach ($need_project as $project_key => $project) {
  187 + if (empty($project['visit_urls'][$j])) {
  188 + continue;
  189 + }
  190 +
  191 + $data = [
  192 + 'ip' => $ips[$project_key]['ip'],
  193 + 'referer' => $this->getReferer($ips[$project_key]['ip_area']),
  194 + 'url' => $project['visit_urls'][$j],
  195 + 'device_port' => $this->get_rand($this->yddzb)
  196 + ];
  197 + Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
  198 + $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
188 } 199 }
  200 + Utils::settle($promises)->wait();
189 201
190 - $data = [  
191 - 'ip' => $ips[$project_key]['ip'],  
192 - 'referer' => $this->getReferer($ips[$project_key]['ip_area']),  
193 - 'url' => $project['visit_urls'][$j],  
194 - 'device_port' => $this->get_rand($this->yddzb)  
195 - ];  
196 - Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);  
197 - $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]); 202 + //每个深度随机等待
  203 + sleep(rand(2, 10));
198 } 204 }
199 - Utils::settle($promises)->wait();  
200 -  
201 - //每个深度随机等待  
202 - sleep(rand(2, 10));  
203 } 205 }
204 - }  
205 206
206 - $page++; 207 + $page++;
  208 + }
  209 + }catch (\Exception $e){
  210 + Log::channel('traffic')->error($e->getMessage());
207 } 211 }
208 } 212 }
209 213