Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Fix "Resource temporarily unavailable" #1319

Merged
merged 2 commits into from
Oct 11, 2017
Merged
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
16 changes: 6 additions & 10 deletions src/Faker/Provider/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,22 @@ public static function image($dir = null, $width = 640, $height = 480, $category
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
fclose($fp);
curl_close($ch);

if ($success) {
fclose($fp);
} else {
if (!$success) {
unlink($filepath);
}

curl_close($ch);
// could not contact the distant URL or HTTP error - fail silently.
return false;
}
} elseif (ini_get('allow_url_fopen')) {
// use remote fopen() via copy()
$success = copy($url, $filepath);
} else {
return new \RuntimeException('The image formatter downloads an image from a remote HTTP server. Therefore, it requires that PHP can request remote hosts, either via cURL or fopen()');
}

if (!$success) {
// could not contact the distant URL or HTTP error - fail silently.
return false;
}

return $fullPath ? $filepath : $filename;
}
}