Example #1
0
 /**
  * 初始化对象
  */
 protected static function init($snId = 0)
 {
     if (!self::$client) {
         if (class_exists("GearmanClient")) {
             self::$client = new GearmanClient();
             foreach (self::$serverArr as $v) {
                 self::$client->addServers($v);
             }
         } else {
             die("Gearman 接口模块不可用");
         }
     }
 }
Example #2
0
 /**
  * 获得Dom操作对象
  */
 public static function getHtmlOrDom($paramArr)
 {
     $options = array('url' => 'http://www.baidu.com/', 'charset' => 'utf-8', 'timeout' => 3, 'isGearman' => false, 'getDom' => false, 'snoopy' => false, 'fileGetContents' => false, 'ungzip' => false, 'referer' => false, 'proxy' => false, 'maxredirs' => 6, 'header' => false);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     #获得页面内容
     if ($isGearman) {
         $htmlStr = API_Gearman::doNormal(array('taskName' => 'adsl_get_contents', 'taskContent' => $url));
     } else {
         if ($snoopy) {
             $htmlStr = self::snoopyFetch(array('url' => $url, 'referer' => $referer, 'proxy' => $proxy, 'maxredirs' => $maxredirs, 'header' => $header));
         } elseif ($fileGetContents) {
             $htmlStr = file_get_contents($url);
         } else {
             $htmlStr = API_Http::curlPage(array('url' => $url, 'timeout' => $timeout));
         }
     }
     if (!$htmlStr) {
         return false;
     }
     if ($ungzip) {
         $htmlStr = API_Item_Base_String::gzdecode(array('input' => $htmlStr));
     }
     if (!$getDom) {
         return $htmlStr;
     }
     #载入处理类
     require_once LJL_API_ROOT . '/Libs/FetchHtml/SimpleHtmlDom.php';
     if ($charset == "UTF-8" || $charset == "utf-8") {
         $htmlStr = mb_convert_encoding($htmlStr, "GBK", "utf-8");
     }
     $dom = new simple_html_dom(null, $lowercase = true, $forceTagsClosed = true, 'GBK');
     //还是用gbk去解析
     $dom->load($htmlStr, $lowercase = true, $stripRN = true);
     return $dom;
 }