<?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($eiCzc, $uHAEV = null) { goto WsuzS; Rk2PA: $this->delay['max'] = $uHAEV; goto wpLa2; WsuzS: if (null === $uHAEV) { $uHAEV = $eiCzc; } goto vPukA; vPukA: $this->delay['min'] = $eiCzc; goto Rk2PA; wpLa2: } public function init() { if (null == $this->queue) { $this->queue = new ArrayQueue(); } } public function register($pQSF_, $cLmLz, $D4BhT = null) { $this->handlers[$pQSF_] = array($cLmLz, $D4BhT); } public function dispatch($pQSF_, $uxJUJ = array(), $StE5h = null) { $this->queue->append($pQSF_, $uxJUJ, $StE5h); } public function onFinish() { } public function name() { return class_basename(static::class); } public function logInfo($trk4v, $cwaKT = null) { goto zGYCy; oJ5oj: echo join(' - ', $VSNlr) . '
'; goto EGr4b; e8Qc6: if (null != $cwaKT) { if (is_string($cwaKT)) { $VSNlr[] = $cwaKT; } else { $VSNlr[] = json_encode($cwaKT, JSON_UNESCAPED_UNICODE); } } goto oJ5oj; SGgOQ: $VSNlr[] = date('Y-m-d H:i:s'); goto S5_ts; qZALn: $VSNlr[] = $trk4v; goto e8Qc6; zGYCy: $VSNlr = array(); goto SGgOQ; S5_ts: $VSNlr[] = '[' . $this->name() . ']'; goto qZALn; EGr4b: } public function logError($trk4v, $cwaKT = null) { goto On9Ix; AgcsG: $VSNlr[] = date('Y-m-d H:i:s'); goto R2Zhf; On9Ix: $VSNlr = array(); goto AgcsG; R2Zhf: $VSNlr[] = '[' . $this->name() . ']'; goto GuCA8; HXBvV: if (null != $cwaKT) { $VSNlr[] = json_encode($cwaKT, JSON_UNESCAPED_UNICODE); } goto AmKi5; GuCA8: $VSNlr[] = $trk4v; goto HXBvV; AmKi5: echo join(' - ', $VSNlr) . '
'; goto XE7nz; XE7nz: } public function run() { while (true) { $bicx_ = $this->queue->poll(); if (empty($bicx_)) { goto cVL7G; C5Ln6: break; goto uP1AM; nxJ4r: $this->logInfo('End'); goto C5Ln6; cVL7G: $this->onFinish(); goto nxJ4r; uP1AM: } if (!isset($this->handlers[$bicx_['handler']])) { $this->logError("Handler {$bicx_['handler']} not registered", $bicx_['param']); continue; } $cLmLz = $this->handlers[$bicx_['handler']][0]; $D4BhT = $this->handlers[$bicx_['handler']][1]; $StE5h = $bicx_['id']; if ($StE5h === null) { if (is_string($bicx_['param']) || is_numeric($bicx_['param'])) { $StE5h = $bicx_['param']; } else { if (is_array($bicx_['param'])) { goto ZGbb0; ZGbb0: $k30iT = array(); goto jrDLq; wa9AM: $StE5h = join(',', $k30iT); goto jsrei; jrDLq: foreach ($bicx_['param'] as $D5qRP => $qGgGl) { if (is_string($qGgGl) || is_numeric($qGgGl)) { } else { $qGgGl = json_encode($qGgGl, JSON_UNESCAPED_UNICODE); } $k30iT[] = "{$D5qRP}:{$qGgGl}"; } goto wa9AM; jsrei: } else { $StE5h = json_encode($bicx_['param'], JSON_UNESCAPED_UNICODE); } } } try { call_user_func_array($cLmLz, array($this, $bicx_['param'], $bicx_['id'])); $this->logInfo("Execute {$bicx_['handler']} {$StE5h}"); } catch (\Exception $RWZxh) { goto CDtJw; E4SGL: if (null !== $D4BhT) { try { $D4BhT($this, $bicx_['param'], $bicx_['id']); } catch (\Exception $RWZxh) { $this->logInfo("Execute Fail for Error Handler {$bicx_['handler']} {$StE5h}", $RWZxh->getMessage()); } } goto iWBO_; CDtJw: var_dump($bicx_); goto fqjuM; fqjuM: $this->logInfo("Execute {$bicx_['handler']} {$StE5h}", $RWZxh->getMessage()); goto E4SGL; iWBO_: } if ($this->delay['max'] > 0) { usleep(rand($this->delay['min'], $this->delay['max']) * 1000); } } } public abstract function setup(); }