From e048b8863786bf0d83689dee2f1b964879ca6a19 Mon Sep 17 00:00:00 2001 From: Erik Berkun-Drevnig Date: Wed, 11 Oct 2017 10:53:48 -0400 Subject: [PATCH 1/2] Fix "Resource temporarily unavailable" When trying to unlink the file after unsuccessful download, a warning is thrown because file is still open --- src/Faker/Provider/Image.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Faker/Provider/Image.php b/src/Faker/Provider/Image.php index 404a45a007..69904ad976 100644 --- a/src/Faker/Provider/Image.php +++ b/src/Faker/Provider/Image.php @@ -84,14 +84,15 @@ 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; - - if ($success) { - fclose($fp); - } else { + fclose($fp); + curl_close($ch); + + if (!$success) { unlink($filepath); + + // could not contact the distant URL or HTTP error - fail silently. + return false; } - - curl_close($ch); } elseif (ini_get('allow_url_fopen')) { // use remote fopen() via copy() $success = copy($url, $filepath); @@ -99,11 +100,6 @@ public static function image($dir = null, $width = 640, $height = 480, $category 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; } } From fb0f2f1ff7fc9bf26c1dce10a1dba4f0d605289a Mon Sep 17 00:00:00 2001 From: Erik Berkun-Drevnig Date: Wed, 11 Oct 2017 11:08:55 -0400 Subject: [PATCH 2/2] Fix whitespace causing build to fail --- src/Faker/Provider/Image.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Faker/Provider/Image.php b/src/Faker/Provider/Image.php index 69904ad976..0458ceb9c3 100644 --- a/src/Faker/Provider/Image.php +++ b/src/Faker/Provider/Image.php @@ -86,10 +86,10 @@ public static function image($dir = null, $width = 640, $height = 480, $category $success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200; fclose($fp); curl_close($ch); - - if (!$success) { + + if (!$success) { unlink($filepath); - + // could not contact the distant URL or HTTP error - fail silently. return false; }