1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace Spider\Lib;
- use Dever;
- class Queue
- {
- public function __construct($method)
- {
- if (!Dever::config('base')->queue) {
- Dever::config('base')->queue = array('method' => $method);
- } else {
- Dever::config('base')->queue['method'] = $method;
- }
-
- Dever::import('queue');
- }
- public function push($url, $config, $num = 0)
- {
- if (strpos($url, '{') !== false && strpos($url, '}') !== false) {
- $this->preg($url, $num, $config);
- } else {
- $this->push_db($url, $config);
- }
- return true;
- }
- public function pop()
- {
- return $this->pop_db();
- }
- private function preg($value, $num, $config)
- {
- $pat = '/{(.*?)}/i';
- preg_match_all($pat, $value, $match);
- if (isset($match[1][0]) && $match[1][0]) {
- if ($num <= 0) $num = 1000;
- parse_str($match[1][0], $param);
- $this->page($param, $match[0][0], $value, $num, $config);
- }
- }
- private function page($param, $replace, $value, $num, $config)
- {
- if (isset($param['page'])) {
- for ($i = $param['page']; $i <= $num; $i++) {
- $url = str_replace($replace, $i, $value);
- $this->push($url, $config);
- }
- } else {
- $this->push(str_replace($replace, '', $value), $config);
- }
- }
- private function push_db($value, $config)
- {
- $config['url'] = $value;
- Dever::push($config);
- }
- private function pop_db()
- {
- return Dever::pop();
- }
- }
|