Skip to content
Browse files

close stream to avoid lock, code clean-up

  • Loading branch information...
1 parent cb38837 commit b95de65bc1be94b15ee22ba10f59d9c1d5baa234 @havvg committed Apr 19, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 Imagine/Data/Loader/StreamLoader.php
View
9 Imagine/Data/Loader/StreamLoader.php
@@ -54,15 +54,16 @@ public function find($path)
* This looks strange, but at least in PHP 5.3.8 it will raise an E_WARNING if the 4th parameter is null.
* fopen() will be called only once with the correct arguments.
*
- * The error suppressing is solely to determ whether the file exists.
+ * The error suppression is solely to determine whether the file exists.
* file_exists() is not used as not all wrappers support stat() to actually check for existing resources.
*/
- if (($this->context and @!fopen($name, 'r', null, $this->context)) || @!fopen($name, 'r')) {
+ if (($this->context && !$resource = @fopen($name, 'r', null, $this->context)) || !$resource = @fopen($name, 'r')) {
throw new NotFoundHttpException('Source image not found.');
}
- $image = $this->imagine->load(file_get_contents($name, null, $this->context));
+ // Closing the opened stream to avoid locking of the resource to find.
+ fclose($resource);
- return $image;
+ return $this->imagine->load(file_get_contents($name, null, $this->context));
}
}

0 comments on commit b95de65

Please sign in to comment.
Something went wrong with that request. Please try again.