diff --git a/EpiCurl.php b/EpiCurl.php index 37d2aa5..0fbbd9c 100644 --- a/EpiCurl.php +++ b/EpiCurl.php @@ -31,7 +31,7 @@ function __construct() 'url' => CURLINFO_EFFECTIVE_URL ); } - + public function addEasyCurl($ch) { $key = $this->getKey($ch); @@ -42,6 +42,16 @@ public function addEasyCurl($ch) $this->startTimer($key); return new EpiCurlManager($key); } + + // simplifies example and allows for additional curl options to be passed in via array + public function addURL($url,$options=array()) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + foreach($options as $option=>$value) { + curl_setopt($ch, $option, $value); + } + return $this->addCurl($ch); + } public function addCurl($ch) { @@ -71,7 +81,7 @@ public function getResult($key = null) { if($key != null) { - if(isset($this->responses[$key])) + if(isset($this->responses[$key]['data'])) { return $this->responses[$key]; } @@ -82,7 +92,7 @@ public function getResult($key = null) usleep(intval($outerSleepInt)); $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement))); $ms=curl_multi_select($this->mc, 0); - if($ms > 0) + if($ms >= CURLM_CALL_MULTI_PERFORM) { do{ $this->execStatus = curl_multi_exec($this->mc, $this->running); @@ -102,7 +112,12 @@ public function getResult($key = null) } return false; } - + + public function cleanupResponses() + { + $this->responses = array(); + } + public static function getSequence() { return new EpiSequence(self::$timers); @@ -138,7 +153,7 @@ private function storeResponses() $this->storeResponse($done); } } - + private function storeResponse($done, $isAsynchronous = true) { $key = $this->getKey($done['handle']); @@ -156,7 +171,7 @@ private function storeResponse($done, $isAsynchronous = true) curl_multi_remove_handle($this->mc, $done['handle']); curl_close($done['handle']); } - + private function startTimer($key) { self::$timers[$key]['start'] = microtime(true); diff --git a/composer.json b/composer.json index da4d8d5..5b47828 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,22 @@ { - "name": "jmathai/twitter-async", - "description": "Twitter-async is a high performance wrapper for Twitter's OAuth API which provides parallel/asynchronous calls.", - "homepage": "http://www.jaisenmathai.com/articles/twitter-async-documentation.html", - "author": "Jaisen Mathai", - "license": "BSD" -} \ No newline at end of file + "name": "jmathai/twitter-async", + "description": "Twitter-async is a high performance wrapper for Twitter's OAuth API which provides parallel/asynchronous calls.", + "homepage": "http://www.jaisenmathai.com/articles/twitter-async-documentation.html", + "authors": [ + { + "name": "Jaisen Mathai", + "homepage": "http://www.jaisenmathai.com/", + "email": "jaisen@jmathai.com", + "role": "Developer" + } + ], + "license": "BSD-3-Clause", + "require": { + "ext-curl": "*" + }, + "autoload": { + "classmap": [""], + "exclude-from-classmap": ["**/tests/**"] + }, + "minimum-stability": "dev" +}