Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing cURL handlers #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/RollingCurl/RollingCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,16 @@ public function execute()
return;
}

$requestHandlers = array();
foreach ($firstBatch as $request) {
// setup the curl request, queue it up, and put it in the active array
$ch = curl_init();
$options = $this->prepareRequestOptions($request);
curl_setopt_array($ch, $options);
curl_multi_add_handle($master, $ch);
$this->activeRequests[(int) $ch] = $request;
$key = (int) $ch;
$this->activeRequests[$key] = $request;
$requestHandlers[$key] = $ch;
}

$active = null;
Expand Down Expand Up @@ -259,19 +262,19 @@ public function execute()
$this->completedRequests[] = $request;
$this->completedRequestCount++;

// start a new request (it's important to do this before removing the old one)
// remove the curl handle that just completed
curl_multi_remove_handle($master, $transfer['handle']);

// start a new request
if ($nextRequest = $this->getNextPendingRequest()) {
// setup the curl request, queue it up, and put it in the active array
$ch = curl_init();
$ch = $requestHandlers[$key];
$options = $this->prepareRequestOptions($nextRequest);
curl_setopt_array($ch, $options);
curl_multi_add_handle($master, $ch);
$this->activeRequests[(int) $ch] = $nextRequest;
}

// remove the curl handle that just completed
curl_multi_remove_handle($master, $transfer['handle']);

// if there is a callback, run it
if (is_callable($this->callback)) {
$callback = $this->callback;
Expand Down