Cassandra\Cluster\Builder::withPort PHP Method

withPort() public method

Specify a different port to be used when connecting to the cluster.
public withPort ( integer $port ) : Builder
$port integer a number between 1 and 65535
return Builder self
    public function withPort($port)
    {
    }

Usage Example

Beispiel #1
0
 /**
  * Establishes connection to existing cluster
  * @param   array $descriptor - connection description, default null
  * @return  bool
  * @throws  \PhalconCassandra\Db\Exception\Cassandra
  */
 public function connect($descriptor = null)
 {
     if ($this->_session) {
         throw new CException('Connection already established');
     }
     if (is_array($descriptor)) {
         $descriptor = array_merge($this->_descriptor, $descriptor);
     } else {
         $descriptor = $this->_descriptor;
     }
     if (empty($descriptor['keyspace'])) {
         throw new CException('Keyspace must be set');
     }
     $cluster = new Builder();
     if (isset($descriptor['host'])) {
         $cluster->withContactPoints($descriptor['host']);
     }
     if (isset($descriptor['port'])) {
         $cluster->withPort($descriptor['port']);
     }
     if (isset($descriptor['consistency'])) {
         $cluster->withDefaultConsistency($descriptor['consistency']);
         $this->setDefaultConsistency($descriptor['consistency']);
     }
     if (isset($descriptor['pageSize'])) {
         $cluster->withDefaultPageSize($descriptor['pageSize']);
     }
     if (isset($descriptor['persistent'])) {
         $cluster->withPersistentSessions($descriptor['persistent']);
     }
     if (isset($descriptor['persistent'])) {
         $cluster->withPersistentSessions($descriptor['persistent']);
     }
     if (isset($descriptor['keepalive'])) {
         $cluster->withTCPKeepalive($descriptor['keepalive']);
     }
     if (isset($descriptor['connectTimeout'])) {
         $cluster->withConnectTimeout($descriptor['connectTimeout']);
     }
     if (isset($descriptor['requestTimeout'])) {
         $cluster->withRequestTimeout($descriptor['requestTimeout']);
     }
     if (isset($descriptor['ioThreads'])) {
         $cluster->withIOThreads($descriptor['ioThreads']);
     }
     if (isset($descriptor['username'], $descriptor['password'])) {
         $cluster->withCredentials($descriptor['username'], $descriptor['password']);
     }
     try {
         $this->_session = $cluster->build()->connect($descriptor['keyspace']);
     } catch (BaseException $e) {
         throw new CException($e->getMessage(), $e->getCode());
     }
     return true;
 }