I'm having difficulty conceptualizing and coding the following scenario. I'm really close but I need that last step...hopefully you can help.
The old method I was using (which worked fine) was 2 classes that each had a cURL request. This was slow so I made a single class that was inherited by the 2 child classes.
Each of the child classes would call parent::runCurl()
In the parent Exchange class I put the following code which I modified from searching Google and reading the help files:
Code: Select all
public function __construct() {
$this->ch = curl_init();
curl_multi_add_handle($_SESSION['curl_mh'],$this->ch);
//$_SESSION['curl_mh'] is initialized during login.
}
private function runCurl() {
$this->full_curl_multi_exec($_SESSION['curl_mh'], $this->curl_active);
while ($this->curl_active && $mrc == CURLM_OK) {
//PHP bug, so run this
if (curl_multi_select($_SESSION['curl_mh']) != -1) {
usleep(100);
}
while(($info = curl_multi_info_read($_SESSION['curl_mh']))) {
echo $info["result"];
if ($info["result"] == CURLE_OK){
$this->content = curl_multi_getcontent($info["handle"]);
echo "here";
print_r($this->content);
}
}
$this->full_curl_multi_exec($_SESSION['curl_mh'], $this->curl_active);
}
}
function full_curl_multi_exec($mh, &$still_running) {
do {
$rv = curl_multi_exec($mh, $still_running);
} while ($rv == CURLM_CALL_MULTI_PERFORM);
return $rv;
}
Does anybody know what's up? Have I even conceptualized this properly? I need it to fetch two requests and process the data when they're both done.
P.S. I should add that each child class has different CURL options and sends to a different url.