gpt4 book ai didi

php - 如何在PHP中获取 sphinx 连接失败错误

转载 作者:行者123 更新时间:2023-12-03 08:28:55 25 4
gpt4 key购买 nike

这是我的代码:

    include_once( "extensions/sphinxapi.php" );
$mode = SPH_MATCH_EXTENDED2;
$host = "localhostt"; //am giving wrong to get error
$port = 9312;
$ranker = SPH_RANK_NONE;
$ranker = SPH_RANK_PROXIMITY_BM25;

$cl = new SphinxClient();
$cl->GetLastError(); //this line is Not working
$testcon=$cl->SetServer ( $host, $port );
if($testcon){ print_r($cl); }else if(!($testcon)) {echo "show error";}
$cl->SetConnectTimeout ( 1 );
$cl->SetArrayResult ( true );
$cl->SetWeights ( array ( 100,50,100,100,100,100,100,100,100,100,100,100,100,100,100));
$cl->SetMatchMode ( $mode );
$cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
$cl->SetRankingMode ($ranker);
$cl->ResetFilters();

sphinx 正常工作。那不是问题。但是,如果我给主机名输入了错误的名称,则它不会显示任何错误。
$host = "localhostt";//like this
$c1->GetLastError(); //not working Gives empty result .
$c1->GetLastWarning(); //not working also gives empty result.

我如何获得连接失败错误。我需要在我的网站上显示错误。谢谢。

最佳答案

你可以试试

$connected = $cl->Open();

当连接失败时,它返回

例如:
  $this->sphinxApiClient = new \SphinxClient();
$this->sphinxApiClient->SetConnectTimeout(self::CONNECTION_TIMEOUT);
$this->sphinxApiClient->SetMaxQueryTime(self::MAX_QUERY_TIME);
$this->sphinxApiClient->SetServer($host, $port);
$connected = $this->sphinxApiClient->Open();

if (!$connected) {
....
} else {
....
}

关于php - 如何在PHP中获取 sphinx 连接失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31801366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com