Sphinx\SphinxClient::setServer PHP Method

setServer() public method

Set searchd host name and port
public setServer ( string $host, integer $port ) : SphinxClient
$host string
$port integer
return SphinxClient
    public function setServer($host, $port = 0)
    {
        if (!is_string($host)) {
            throw new \InvalidArgumentException('Host name must be a string.');
        }
        if ($host[0] === '/') {
            $this->path = 'unix://' . $host;
            return $this;
        }
        if (substr($host, 0, 7) === 'unix://') {
            $this->path = $host;
            return $this;
        }
        $this->host = $host;
        $port = intval($port);
        if ($port < 0 || $port >= 65536) {
            throw new \InvalidArgumentException('Port number must be an integer between 0 and 65536.');
        }
        $this->port = $port ?: 9312;
        $this->path = '';
        return $this;
    }

Usage Example

 /**
  * Constructor
  *
  * @param string $host   Sphinx host
  * @param string $port   Sphinx port
  * @param string $socket UNIX socket. Not required
  *
  * @throws NoSphinxAPIException If class SphinxClient does not exists
  */
 public function __construct($host, $port, $socket = null)
 {
     $this->host = $host;
     $this->port = $port;
     $this->socket = $socket;
     $this->sphinx = new SphinxClient();
     if (!is_null($this->socket)) {
         $this->sphinx->setServer($this->socket);
     } else {
         $this->sphinx->setServer($this->host, $this->port);
     }
 }
All Usage Examples Of Sphinx\SphinxClient::setServer