Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When in synchronous mode use curl instead of multi curl.

Closes gh-49
  • Loading branch information...
commit c365e613bd474ba1012e82e9d50d6c5cb84bfe72 1 parent aaff245
@jmathai authored
View
40 EpiCurl.php
@@ -32,6 +32,17 @@ function __construct()
);
}
+ public function addEasyCurl($ch)
+ {
+ $key = $this->getKey($ch);
+ $this->requests[$key] = $ch;
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback'));
+ $done = array('handle' => $ch);
+ $this->storeResponse($done, false);
+ $this->startTimer($key);
+ return new EpiCurlManager($key);
+ }
+
public function addCurl($ch)
{
$key = $this->getKey($ch);
@@ -117,6 +128,7 @@ private function headerCallback($ch, $header)
$val = preg_replace('/^\W+/','',substr($_header, $colonPos));
$this->responses[$this->getKey($ch)]['headers'][$key] = $val;
}
+ $this->storeResponse($ch);
return strlen($header);
}
@@ -124,16 +136,26 @@ private function storeResponses()
{
while($done = curl_multi_info_read($this->mc))
{
- $key = (string)$done['handle'];
- $this->stopTimer($key, $done);
- $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']);
- foreach($this->properties as $name => $const)
- {
- $this->responses[$key][$name] = curl_getinfo($done['handle'], $const);
- }
- curl_multi_remove_handle($this->mc, $done['handle']);
- curl_close($done['handle']);
+ $this->storeResponse($done);
+ }
+ }
+
+ private function storeResponse($ch, $isAsynchronous = true)
+ {
+ $key = $this->getKey($ch['handle']);
+ $this->stopTimer($key, $ch);
+ if($isAsynchronous)
+ $this->responses[$key]['data'] = curl_multi_getcontent($ch['handle']);
+ else
+ $this->responses[$key]['data'] = curl_exec($ch['handle']);
+
+ foreach($this->properties as $name => $const)
+ {
+ $this->responses[$key][$name] = curl_getinfo($ch['handle'], $const);
}
+ if($isAsynchronous)
+ curl_multi_remove_handle($this->mc, $ch['handle']);
+ curl_close($ch['handle']);
}
private function startTimer($key)
View
14 EpiOAuth.php
@@ -193,12 +193,20 @@ protected function generateSignature($method = null, $url = null, $params = null
return $this->signString($signatureBaseString);
}
+ protected function executeCurl($ch)
+ {
+ if($this->isAsynchronous)
+ return $this->curl->addCurl($ch);
+ else
+ return $this->curl->addEasyCurl($ch);
+ }
+
protected function httpDelete($url, $params) {
$this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
- $resp = $this->curl->addCurl($ch);
+ $resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;
}
@@ -216,7 +224,7 @@ protected function httpGet($url, $params = null)
}
$this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url);
- $resp = $this->curl->addCurl($ch);
+ $resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;
@@ -233,7 +241,7 @@ protected function httpPost($url, $params = null, $isMultipart)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
else
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
- $resp = $this->curl->addCurl($ch);
+ $resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;
View
1  EpiTwitter.php
@@ -247,7 +247,6 @@ class EpiTwitterException extends Exception
public static function raise($response, $debug)
{
$message = $response->data;
-
switch($response->code)
{
case 400:
View
5 tests/EpiTwitterTest.php
@@ -20,8 +20,11 @@ function setUp()
// key and secret for a test app (don't really care if this is public)
$this->twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this->token, $this->secret);
$this->twitterObjUnAuth = new EpiTwitter($this->consumer_key, $this->consumer_secret);
- $this->twitterObjBasic = new EpiTwitter();
$this->twitterObjBadAuth = new EpiTwitter('foo', 'bar', 'foo', 'bar');
+ // these 3 lines turn on asynchronous calls
+ $this->twitterObj->useAsynchronous(true);
+ $this->twitterObjUnAuth->useAsynchronous(true);
+ $this->twitterObjBadAuth->useAsynchronous(true);
}
function testGetAuthenticateurl()
Please sign in to comment.
Something went wrong with that request. Please try again.