Exemplo n.º 1
0
 /**
  * 返回APS实例
  *
  * @return APS
  */
 public static function get_instance()
 {
     if (self::$instance === NULL) {
         self::$instance = new APS();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 public function replaceWordsStr($strWords, $time = 200)
 {
     if ($strWords && APP_NAME != 'my-job') {
         $client = APS::get_instance()->get_aps_client('mss');
         $client->start_request('stringmatch/stringMatchService/multiSearch', array(array($strWords)), $rs);
         $pending = $client->wait_for_replies($time);
         if ($pending > 0) {
             return $strWords;
         }
         $rs = json_decode($rs, true);
         if (!empty($rs) && !empty($rs[0])) {
             foreach ($rs[0] as $blackWord) {
                 $hit_black[] = $blackWord[0];
             }
             $strWords = str_replace($hit_black, '**', $strWords);
         }
         return $strWords;
     }
 }
Exemplo n.º 3
0
 /**
  * 等待应答
  *
  * @param  integer $timeout   请求超时时间(毫秒)
  * @param  boolean $autofetch 是否自动获取结果
  * @param  boolean $keep      是否保留结果
  * @return integer            未收到应答的请求数
  */
 public function wait_for_replies($timeout = -1, $autofetch = TRUE, $keep = FALSE)
 {
     //页面清除cache
     //是否开启页面清除cache
     $open_clear_page_cache = APF::get_instance()->get_config('open_clear_page_cache');
     //要接受的getkey
     $clear_page_cache_key = APF::get_instance()->get_config('clear_page_cache_key');
     //要接受的getval
     $clear_page_cache_val = APF::get_instance()->get_config('clear_page_cache_val');
     if ($open_clear_page_cache) {
         //如果接受设定的get方法中有值不为空,则清空当前cache
         if (APF::get_instance()->get_request()) {
             $isclearcache = APF::get_instance()->get_request()->get_parameter($clear_page_cache_key);
             if ($isclearcache == $clear_page_cache_val) {
                 apf_require_class('GlobalFunc');
                 //判断ip段
                 if (GlobalFunc::is_allow_debug()) {
                     $timeout = -1;
                 }
             }
         }
     }
     try {
         if (APS::get_instance()->get_zmq_enabled()) {
             $poll = new ZMQPoll();
             //            foreach (self::$sockets as $socket) {
             //                $poll->add($socket, ZMQ::POLL_IN);
             //            }
             $poll->add($this->socket, ZMQ::POLL_IN);
             $start = APS_Functions::aps_millitime();
             $pending = count($this->requests);
             $readable = $writeable = array();
             while ($pending > 0 && $timeout > 0) {
                 $events = $poll->poll($readable, $writeable, $timeout);
                 if ($events == 0) {
                     break;
                 }
                 foreach ($readable as $socket) {
                     $this->process_reply($socket);
                     --$pending;
                 }
                 $millitime = APS_Functions::aps_millitime();
                 $timeout -= $millitime - $start;
                 if ($timeout <= 0) {
                     break;
                 }
                 $start = $millitime;
             }
         }
         if ($autofetch) {
             $this->fetch_all_replies($keep);
             $pending = 0;
         }
     } catch (Exception $e) {
         error_log(print_r('Caught exception: ' . $e->getMessage() . "\n", 1), 3, '/tmp/replaceWords.log');
     }
     return $pending;
 }
Exemplo n.º 4
0
 public static function get_illegal_words($text, $time = 200)
 {
     $client = APS::get_instance()->get_aps_client('mss');
     $client->start_request('stringmatch/stringMatchService/multiSearch', array(array($text)), $rs);
     $pending = $client->wait_for_replies($time);
     if ($pending > 0) {
         return array();
     }
     $hit_black = array();
     $rs = json_decode($rs, true);
     if (!empty($rs) && !empty($rs[0])) {
         foreach ($rs[0] as $blackWord) {
             $hit_black[] = $blackWord[0];
         }
     }
     return $hit_black;
 }