Sphinx php api无法正常工作

Fur*_*ore 3 php sphinx

我一直试图通过PHP使用sphinx,到目前为止我绝对没有运气.

sphinx本身正在按预期运行(我通过linux终端的搜索命令正在运行)

Engine_Api_SphinxClient是安装包附带的sphinx的常规php api.唯一的区别是班级的命名.

    // Connect to sphinx server
    $sp = new \Engine_Api_SphinxClient();

    // Set the server
    $sp->SetServer('localhost', 9312);

    // SPH_MATCH_ALL will match all words in the search term
    $sp->SetMatchMode(SPH_MATCH_ANY);

    // We want an array with complete per match information including the document ids
    $sp->SetArrayResult(true);

    $sp->setFieldWeights(array(
        'thesis'=>2,
        'body'=>1
    ));

    /**
    * Run the search query. Here the first argument is the search term
    * and the second is the name of the index to search in.
    * Search term can come from a search form
    */
    $results = $sp->Query('gun', 'test1');
    debug($results);
Run Code Online (Sandbox Code Playgroud)

该setServer中的9312是sphinx配置文件中定义的监听帖子.调试行给出"false",我看到以下警告和通知:

Errors

Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 998
Warning: assert(): Assertion failed in /library/Engine/Api/SphinxClient.php on line 177
Warning: assert(): Assertion failed in /library/Engine/Api/SphinxClient.php on line 177
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1006
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1054
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1070
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 564
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 569
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 477
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 478
Warning: fclose() expects parameter 1 to be resource, null given in /library/Engine/Api/SphinxClient.php on line 478
Run Code Online (Sandbox Code Playgroud)

我怀疑它与这四个通知有关.如果有人能提供关于问题的提示,我将不胜感激.

bar*_*ter 7

如果你自己重命名了类,你是否也改变了构造函数的名称(第430行)?

我怀疑构造函数没有被调用,所以_socket没有被初始化(这在构造函数中发生)

(如果这是问题,你可以将函数重命名为__construct(),这样它就不依赖于调用类的内容 .http://php.net/manual/en/language.oop5.decon.php )