<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\QuickRun\Crawl; abstract class AbstractCrawler { protected $queue = null; protected $handlers = array(); protected $delay = array('min' => 0, 'max' => 0); public function setDelay($lUqNY, $Kz9yO = null) { goto HEbUJ; IBqob: $this->delay['max'] = $Kz9yO; goto stb0Q; Zi3cZ: $this->delay['min'] = $lUqNY; goto IBqob; HEbUJ: if (null === $Kz9yO) { $Kz9yO = $lUqNY; } goto Zi3cZ; stb0Q: } public function init() { if (null == $this->queue) { $this->queue = new ArrayQueue(); } } public function register($Q5AuL, $n3l39, $FL_9i = null) { $this->handlers[$Q5AuL] = array($n3l39, $FL_9i); } public function dispatch($Q5AuL, $f_HcG = array(), $D4D3g = null) { $this->queue->append($Q5AuL, $f_HcG, $D4D3g); } public function onFinish() { } public function name() { return class_basename(static::class); } public function logInfo($pwDm3, $xJzrK = null) { goto qhiYi; cwE3e: $vVV3u[] = $pwDm3; goto R6J2P; qhiYi: $vVV3u = array(); goto q768r; R6J2P: if (null != $xJzrK) { if (is_string($xJzrK)) { $vVV3u[] = $xJzrK; } else { $vVV3u[] = json_encode($xJzrK, JSON_UNESCAPED_UNICODE); } } goto KXrBe; KXrBe: echo join(' - ', $vVV3u) . '
'; goto lsk4m; EI20N: $vVV3u[] = '[' . $this->name() . ']'; goto cwE3e; q768r: $vVV3u[] = date('Y-m-d H:i:s'); goto EI20N; lsk4m: } public function logError($pwDm3, $xJzrK = null) { goto XbgyT; XqtnP: $vVV3u[] = date('Y-m-d H:i:s'); goto qLZYS; qLZYS: $vVV3u[] = '[' . $this->name() . ']'; goto IUZHf; fbwav: if (null != $xJzrK) { $vVV3u[] = json_encode($xJzrK, JSON_UNESCAPED_UNICODE); } goto MG_Hq; XbgyT: $vVV3u = array(); goto XqtnP; MG_Hq: echo join(' - ', $vVV3u) . '
'; goto vnxSR; IUZHf: $vVV3u[] = $pwDm3; goto fbwav; vnxSR: } public function run() { while (true) { $ZnNP5 = $this->queue->poll(); if (empty($ZnNP5)) { goto D5C7G; M9uvp: break; goto rmnof; D5C7G: $this->onFinish(); goto Qqql8; Qqql8: $this->logInfo('End'); goto M9uvp; rmnof: } if (!isset($this->handlers[$ZnNP5['handler']])) { $this->logError("Handler {$ZnNP5['handler']} not registered", $ZnNP5['param']); continue; } $n3l39 = $this->handlers[$ZnNP5['handler']][0]; $FL_9i = $this->handlers[$ZnNP5['handler']][1]; $D4D3g = $ZnNP5['id']; if ($D4D3g === null) { if (is_string($ZnNP5['param']) || is_numeric($ZnNP5['param'])) { $D4D3g = $ZnNP5['param']; } else { if (is_array($ZnNP5['param'])) { goto umA8D; lTQ5Z: $D4D3g = join(',', $sTypg); goto ZB8lj; quUdg: foreach ($ZnNP5['param'] as $QBy8K => $cG5OI) { if (is_string($cG5OI) || is_numeric($cG5OI)) { } else { $cG5OI = json_encode($cG5OI, JSON_UNESCAPED_UNICODE); } $sTypg[] = "{$QBy8K}:{$cG5OI}"; } goto lTQ5Z; umA8D: $sTypg = array(); goto quUdg; ZB8lj: } else { $D4D3g = json_encode($ZnNP5['param'], JSON_UNESCAPED_UNICODE); } } } try { call_user_func_array($n3l39, array($this, $ZnNP5['param'], $ZnNP5['id'])); $this->logInfo("Execute {$ZnNP5['handler']} {$D4D3g}"); } catch (\Exception $Q19lV) { goto a9iQI; AxASJ: if (null !== $FL_9i) { try { $FL_9i($this, $ZnNP5['param'], $ZnNP5['id']); } catch (\Exception $Q19lV) { $this->logInfo("Execute Fail for Error Handler {$ZnNP5['handler']} {$D4D3g}", $Q19lV->getMessage()); } } goto nS_HU; a9iQI: var_dump($ZnNP5); goto dLXJ7; dLXJ7: $this->logInfo("Execute {$ZnNP5['handler']} {$D4D3g}", $Q19lV->getMessage()); goto AxASJ; nS_HU: } if ($this->delay['max'] > 0) { usleep(rand($this->delay['min'], $this->delay['max']) * 1000); } } } public abstract function setup(); }