略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SphinxClient::setServer

2024-12-23

SphinxClient::setServer

(PECL sphinx >= 0.1.0)

SphinxClient::setServer设置searchd的主机名和TCP端口

说明

public SphinxClient::setServer ( string $server , int $port ) : bool

设置searchd的主机名和TCP端口。此后的所有请求都使用新的主机和端口设置。默认的主机和端口分别是“localhost”和3312.

参数

server

IP 或者主机名.

port

端口.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 1 note

up
-10
craig dot constable at gmail dot com
6 years ago
<?php
   
//Here is an example of using the Sphinx api client
   
$server = "192.168.0.100:3306";
   
$username = "johnsmith";
   
$password = "Password1";
   
$database = "customers";
    function
newSQL() {
        global
$server, $username, $password, $database;
       
$con = new mysqli($server, $username, $password, $database);
        return
$con;
    }

    include(
'sphinxapi.php');

   
$search = '@postcode 2012';
   
$s = new SphinxClient;
   
$s->SetServer("192.168.0.100", 9312);
   
$s->SetMatchMode(SPH_MATCH_EXTENDED2);
   
$s->SetSortMode (SPH_SORT_EXTENDED,'@random');
   
$s->SetLimits(0, $times);
   
$index = 'main:delta';
   
$result = $s->Query($search, $index);

    if (
$result['total'] > 0) {
        foreach (
$result['matches'] as $id => $other) {
           
$people .= "pid=$id OR ";   
        }
       
$people = substr($people, 0, -4);
    }

   
$mysqli = newSQL();
   
$mysqliResult = $mysqli->query("SELECT `pid`, `name`, `postcode` FROM `profiles` WHERE ($people)");
   
//Do something with $mysqliResult
   
$mysqli->close();
?>

官方地址:https://www.php.net/manual/en/sphinxclient.setserver.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3