Skip to content

Commit

Permalink
clear the curl handle after closing it
Browse files Browse the repository at this point in the history
  • Loading branch information
mlebkowski committed Feb 13, 2015
1 parent b524d13 commit a1d2c5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/Facebook/HttpClients/FacebookCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public function version()
public function close()
{
curl_close($this->curl);

// closed handle has to be initialized again
$this->curl = null;
}

}
28 changes: 14 additions & 14 deletions src/Facebook/HttpClients/FacebookCurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class FacebookCurlHttpClient implements FacebookHttpable
/**
* @var FacebookCurl Procedural curl as object
*/
protected static $facebookCurl;
protected $facebookCurl;

/**
* @var boolean If IPv6 should be disabled
Expand All @@ -87,14 +87,14 @@ class FacebookCurlHttpClient implements FacebookHttpable
*/
public function __construct(FacebookCurl $facebookCurl = null)
{
self::$facebookCurl = $facebookCurl ?: new FacebookCurl();
$this->facebookCurl = $facebookCurl ?: new FacebookCurl();
self::$disableIPv6 = self::$disableIPv6 ?: false;
}

/**
* Disable IPv6 resolution
*/
public function disableIPv6()
public static function disableIPv6()
{
self::$disableIPv6 = true;
}
Expand Down Expand Up @@ -195,16 +195,16 @@ public function openConnection($url, $method = 'GET', $parameters = array())
$options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
}

self::$facebookCurl->init();
self::$facebookCurl->setopt_array($options);
$this->facebookCurl->init();
$this->facebookCurl->setopt_array($options);
}

/**
* Closes an existing curl connection
*/
public function closeConnection()
{
self::$facebookCurl->close();
$this->facebookCurl->close();
}

/**
Expand All @@ -213,17 +213,17 @@ public function closeConnection()
public function tryToSendRequest()
{
$this->sendRequest();
$this->curlErrorMessage = self::$facebookCurl->error();
$this->curlErrorCode = self::$facebookCurl->errno();
$this->responseHttpStatusCode = self::$facebookCurl->getinfo(CURLINFO_HTTP_CODE);
$this->curlErrorMessage = $this->facebookCurl->error();
$this->curlErrorCode = $this->facebookCurl->errno();
$this->responseHttpStatusCode = $this->facebookCurl->getinfo(CURLINFO_HTTP_CODE);
}

/**
* Send the request and get the raw response from curl
*/
public function sendRequest()
{
$this->rawResponse = self::$facebookCurl->exec();
$this->rawResponse = $this->facebookCurl->exec();
}

/**
Expand Down Expand Up @@ -297,10 +297,10 @@ public static function headersToArray($rawHeaders)
*/
private function getHeaderSize()
{
$headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE);
$headerSize = $this->facebookCurl->getinfo(CURLINFO_HEADER_SIZE);
// This corrects a Curl bug where header size does not account
// for additional Proxy headers.
if ( self::needsCurlProxyFix() ) {
if ( $this->needsCurlProxyFix() ) {
// Additional way to calculate the request body size.
if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) {
$headerSize = mb_strlen($this->rawResponse) - $m[1];
Expand All @@ -318,9 +318,9 @@ private function getHeaderSize()
*
* @return boolean
*/
private static function needsCurlProxyFix()
private function needsCurlProxyFix()
{
$ver = self::$facebookCurl->version();
$ver = $this->facebookCurl->version();
$version = $ver['version_number'];

return $version < self::CURL_PROXY_QUIRK_VER;
Expand Down

0 comments on commit a1d2c5b

Please sign in to comment.