Skip to content

Commit

Permalink
Merge ebf5b7b into fb6724d
Browse files Browse the repository at this point in the history
  • Loading branch information
driskell committed Sep 8, 2020
2 parents fb6724d + ebf5b7b commit ed9e8b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/CopyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CopyRequest extends BaseRequest
/** @var resource<stream<plainfile>> */
private $fp;

private $success = false;
private $success = true;

protected static $defaultCurlOptions = array(
CURLOPT_HTTPGET => true,
Expand Down Expand Up @@ -69,6 +69,17 @@ public function makeSuccess()
*/
public function getCurlOptions()
{
if ($this->fp) {
fclose($this->fp);
}
$this->success = false;
$this->fp = fopen($this->destination, 'wb');
if (!$this->fp) {
throw new FetchException(
'The file could not be written to ' . $this->destination
);
}

$curlOpts = parent::getCurlOptions();
$curlOpts[CURLOPT_FILE] = $this->fp;
return $curlOpts;
Expand All @@ -87,13 +98,6 @@ public function setDestination($destination)
}

$this->createDir($destination);

$this->fp = fopen($destination, 'wb');
if (!$this->fp) {
throw new FetchException(
'The file could not be written to ' . $destination
);
}
}

private function createDir($fileName)
Expand Down
5 changes: 4 additions & 1 deletion src/CurlMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public function setRequests(array $requests)
public function setupEventLoop()
{
while (count($this->unused) > 0 && count($this->requests) > 0) {
$request = array_pop($this->requests);
// Process request using a clone to ensure any memory we cause it to allocate is freed after we unset
// Otherwise, memory is still held for all requests due to it existing on the callstack
// Callers should not need to know this though
$request = clone array_pop($this->requests);
$ch = array_pop($this->unused);
$index = (int)$ch;

Expand Down

0 comments on commit ed9e8b1

Please sign in to comment.