Exemplo n.º 1
0
 public function testOthers()
 {
     $this->assertNull($this->object->project);
     $this->object->setProject('demo');
     $this->assertEquals('demo', $this->object->getProject());
     $this->object->setTimeout(0);
     $this->assertFalse($this->object->hasRespond());
     $this->object->sendCommand(CMD_OK);
     $this->assertFalse($this->object->hasRespond());
     $this->object->sendCommand(CMD_SEARCH_GET_DB);
     usleep(50000);
     $this->assertTrue($this->object->hasRespond());
     $res = $this->object->respond;
     $this->assertEquals(CMD_OK_DB_INFO, $res->arg);
     $this->assertEquals('Database()', $res->buf);
     // read timeout
     try {
         stream_set_timeout($this->object->socket, 2);
         $this->object->getRespond();
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertRegExp('/timeout/', $e->getMessage());
     // send cmd
     $this->object->reopen();
     $this->object->project = 'demo';
     $cmd = new XSCommand(array('cmd' => CMD_QUERY_GET_STRING, 'buf' => 'hello'));
     $res = $this->object->execCommand($cmd);
     $this->assertEquals(CMD_OK_QUERY_STRING, $res->arg);
     $this->assertEquals('Xapian::Query(Zhello:(pos=1))', $res->buf);
     // test unimp cmd
     try {
         $e = null;
         $this->object->execCommand(array('cmd' => CMD_INDEX_SUBMIT));
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertEquals('Command not implemented', $e->getMessage());
     // test io closed
     try {
         $e = null;
         $err = error_reporting(0);
         fclose($this->object->socket);
         $this->object->sendCommand(CMD_INDEX_SUBMIT);
     } catch (XSException $e) {
     }
     $this->assertInstanceOf('XSException', $e);
     $this->assertRegExp('/unknown/', $e->getMessage());
     error_reporting($err);
 }
Exemplo n.º 2
0
 /**
  * 连接搜索服务端并初始化
  * 每次重新连接后所有的搜索语句相关设置均被还原
  * @param string $conn
  * @see XSServer::open
  */
 public function open($conn)
 {
     parent::open($conn);
     $this->_prefix = array();
     $this->_fieldSet = false;
     $this->_lastCount = false;
 }
Exemplo n.º 3
0
/**
 * 命令函数: 重连或新建服务端连接
 * @param string $args
 */
function cmd_open($args)
{
    global $server;
    if (empty($args)) {
        if (!$server instanceof XSServer) {
            echo "  请问要打开什么服务端? (索引默认端口:8383, 搜索默认端口:8384)\n";
            echo "  用法: open <port>|<host:port>|<path>|<search|index>\n";
            return;
        }
        $res = $server->reopen();
        echo "  重新打开服务端连接\n";
    } else {
        $args == 'index' && ($args = '8383');
        $args == 'search' && ($args = '8384');
        $server = new XSServer($args);
        echo "  已打开服务端连接: {$args}\n";
    }
    $server->setTimeout(0);
}
Exemplo n.º 4
0
 public function __destruct()
 {
     if ($this->_rebuild === true) {
         try {
             $this->endRebuild();
         } catch (Exception $e) {
         }
     }
     foreach (self::$_adds as $srv) {
         $srv->close();
     }
     self::$_adds = array();
     parent::__destruct();
 }
Exemplo n.º 5
0
 /**
  * 析构函数
  * 在此自动关闭开启的 rebuild
  */
 public function __destruct()
 {
     if ($this->_rebuild === true) {
         try {
             $this->endRebuild();
         } catch (Exception $e) {
         }
     }
     parent::__destruct();
 }