Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ $nodes = [
'timeout' => 30, // write/recv timeout, default 30, stream transport only
'persistent' => true, // use persistent PHP connection, default false, stream transport only
],
[ // advanced way, using SSL
[ // advanced way, using SSL(TLS)
'class' => 'Cassandra\Connection\Stream', // "class" must be defined as "Cassandra\Connection\Stream" for ssl or tls
'host' => 'ssl://10.205.48.70',// or 'tls://10.205.48.70'
'port' => 9042,
'username' => 'admin',
'password' => 'pass',
//disable certificate verification
'ssl' => ['verify_peer'=>false,'verify_peer_name'=>false],
//with SSL certificate validation, no name check
//'ssl' => ['cafile' => 'cassandra.pem', 'verify_peer_name'=>false]
],
];

Expand Down
11 changes: 8 additions & 3 deletions src/Connection/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ public function __construct(array $options) {
protected function _connect() {
if (!empty($this->_stream)) return $this->_stream;

$this->_stream = $this->_options['persistent']
? pfsockopen($this->_options['host'], $this->_options['port'], $errorCode, $errorMessage, $this->_options['connectTimeout'])
: fsockopen($this->_options['host'], $this->_options['port'], $errorCode, $errorMessage, $this->_options['connectTimeout']);
$context = stream_context_create();
if (isset($this->_options['ssl'])){
foreach($this->_options['ssl'] as $optname => $optval)
stream_context_set_option($context, 'ssl', $optname, $optval);
}

$connFlag = $this->_options['persistent'] ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT ;
$this->_stream = stream_socket_client($this->_options['host'].':'. $this->_options['port'], $errorCode, $errorMessage, $this->_options['connectTimeout'], $connFlag, $context);

if ($this->_stream === false){
throw new StreamException($errorMessage, $errorCode);
Expand Down