From e66566182b207a4a8b11dbd101bd84a20df0245c Mon Sep 17 00:00:00 2001 From: hugh-lee <525803178@qq.com> Date: Mon, 31 Aug 2015 10:26:35 +0800 Subject: [PATCH 1/2] stream_socket_client: On success a stream resource is returned which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()), FALSE on failure. --- Connection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Connection.php b/Connection.php index a004d4a1b..731c755f9 100644 --- a/Connection.php +++ b/Connection.php @@ -245,7 +245,7 @@ public function __sleep() */ public function getIsActive() { - return $this->_socket !== null; + return is_resource($this->_socket); } /** @@ -255,7 +255,7 @@ public function getIsActive() */ public function open() { - if ($this->_socket !== null) { + if ($this->isActive) { return; } $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; @@ -288,7 +288,7 @@ public function open() */ public function close() { - if ($this->_socket !== null) { + if ($this->isActive) { $connection = ($this->unixSocket ?: $this->hostname . ':' . $this->port) . ', database=' . $this->database; \Yii::trace('Closing DB connection: ' . $connection, __METHOD__); $this->executeCommand('QUIT'); From 518c0ddd5e9db23bf21d06ec813e332dc769e8b6 Mon Sep 17 00:00:00 2001 From: hugh-lee <525803178@qq.com> Date: Mon, 31 Aug 2015 14:59:28 +0800 Subject: [PATCH 2/2] add socketClientFlags --- Connection.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Connection.php b/Connection.php index 731c755f9..30b31543d 100644 --- a/Connection.php +++ b/Connection.php @@ -227,6 +227,12 @@ class Connection extends Component */ private $_socket; + /** + * @var integer Bitmask field which may be set to any combination of connection flags. Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT. + * @var [type] + */ + public $socketClientFlags = STREAM_CLIENT_CONNECT; + /** * Closes the connection when this component is being serialized. @@ -264,7 +270,8 @@ public function open() $this->unixSocket ? 'unix://' . $this->unixSocket : 'tcp://' . $this->hostname . ':' . $this->port, $errorNumber, $errorDescription, - $this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout") + $this->connectionTimeout ? $this->connectionTimeout : ini_get("default_socket_timeout"), + $this->socketClientFlags ); if ($this->_socket) { if ($this->dataTimeout !== null) {