Skip to content
Closed
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
15 changes: 11 additions & 4 deletions Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -245,7 +251,7 @@ public function __sleep()
*/
public function getIsActive()
{
return $this->_socket !== null;
return is_resource($this->_socket);
}

/**
Expand All @@ -255,7 +261,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;
Expand All @@ -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) {
Expand All @@ -288,7 +295,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');
Expand Down