Skip to content

Commit

Permalink
Workaround for HHVM.
Browse files Browse the repository at this point in the history
HHVM's implementation of socket_create returns a resource of type "stream"
instead of type "socket" causing \Net\Gearman\Connection::isConnected to
return false even when the connection is a valid resource.

See: facebook/hhvm#4036
  • Loading branch information
Daniel Bruce committed Nov 2, 2015
1 parent 037f09d commit 431ab1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class Connection
*/
protected static $multiByteSupport = null;

public static $validResources = array(
'socket' => true,
'stream' => true
);

/**
* Constructor.
*/
Expand Down Expand Up @@ -375,7 +380,7 @@ public static function isConnected($conn)
{
return (is_null($conn) !== true &&
is_resource($conn) === true &&
strtolower(get_resource_type($conn)) == 'socket');
!empty(self::$validResources[strtolower(get_resource_type($conn))]));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function testDefaultConnect()
}

$this->assertInternalType('resource', $connection);
$this->assertEquals('socket', strtolower(get_resource_type($connection)));

$this->assertTrue(in_array(strtolower(get_resource_type($connection)), Connection::$validResources));
$this->assertTrue(Connection::isConnected($connection));

Connection::close($connection);
Expand Down

0 comments on commit 431ab1d

Please sign in to comment.