Skip to content

Commit

Permalink
Merge pull request #69 from mkraemer/master
Browse files Browse the repository at this point in the history
Achieve compatibility with PHP 5.6
  • Loading branch information
fennb committed Sep 30, 2014
2 parents 96ce5fc + 7d37d7a commit 3fa2831
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions lib/Phirehose.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,21 +632,9 @@ protected function connect()
$scheme = ($urlParts['scheme'] == 'https') ? 'ssl://' : 'tcp://';
$port = ($urlParts['scheme'] == 'https') ? $this->secureHostPort : $this->hostPort;

/**
* We must perform manual host resolution here as Twitter's IP regularly rotates (ie: DNS TTL of 60 seconds) and
* PHP appears to cache it the result if in a long running process (as per Phirehose).
*/
$streamIPs = gethostbynamel($urlParts['host']);
if(empty($streamIPs)) {
throw new PhirehoseNetworkException("Unable to resolve hostname: '" . $urlParts['host'] . '"');
}

// Choose one randomly (if more than one)
$this->log('Resolved host ' . $urlParts['host'] . ' to ' . implode(', ', $streamIPs));
$streamIP = $streamIPs[rand(0, (count($streamIPs) - 1))];
$this->log("Connecting to {$scheme}{$streamIP}, port={$port}, connectTimeout={$this->connectTimeout}");
$this->log("Connecting to {$scheme}{$urlParts['host']}, port={$port}, connectTimeout={$this->connectTimeout}");

@$this->conn = fsockopen($scheme . $streamIP, $port, $errNo, $errStr, $this->connectTimeout);
@$this->conn = fsockopen($scheme . $urlParts['host'], $port, $errNo, $errStr, $this->connectTimeout);

// No go - handle errors/backoff
if (!$this->conn || !is_resource($this->conn)) {
Expand All @@ -667,7 +655,7 @@ protected function connect()
}

// TCP connect OK, clear last error (if present)
$this->log('Connection established to ' . $streamIP);
$this->log('Connection established to ' . $urlParts['host']);
$this->lastErrorMsg = NULL;
$this->lastErrorNo = NULL;

Expand Down

0 comments on commit 3fa2831

Please sign in to comment.