|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50373 GD: image* should work with stream handles
Submitted: 2009-12-03 12:31 UTC Modified: 2010-04-28 16:44 UTC
From: rugkiks at gmail dot com Assigned: pajoye (profile)
Status: Duplicate Package: *General Issues
PHP Version: 5.3.1 OS: GNU/Linux
Private report: No CVE-ID: None
 [2009-12-03 12:31 UTC] rugkiks at gmail dot com

Apparently there is not way to lock files while writing to them.

I'd like to see a similar behavior like the flags in

Maybe the file actually get's locked. I can't test it.

Reproduce code:
From manual page: function.imagepng#Description


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-03 16:39 UTC]
I'm curious why you want this.  Locking is almost never the right 
solution for a web app.  Writing to a temp file and then atomically 
rename it into its final destination.  Adding locks to every library 
function PHP can call that can potentially write files is not feasible.
 [2009-12-03 20:25 UTC]
Same here, I don't see how we could do that for every simple file related functions. Please follow Rasmus' advice here, best possible solution.
 [2009-12-03 23:55 UTC] rugkiks at gmail dot com
It's the blocking feature i'm after. When the image is updating, 
other fopen's needs to get blocked. It makes my code much more 

Also, you can do this with ImageMagick, since it allows you to 
supply the file handle yourself

The only reason why i'm requesting this feature to GD, is because of 
GD's speed.

rasmus: The renaming-method is nice. But in my case, i need the 
users to be blocked until the image is ready. Not just show the old 
one, or return a 404. I can program my way out of it, but it's 

I guess i'm saying that it would be nice with a for GD.

Thank you for the response.
 [2009-12-04 00:02 UTC]
Let see if we can get something non intrusive without adding yet another option to this function (already confusing :).
 [2009-12-04 00:18 UTC]
I still don't think it is a big deal.  Just create a filename.lck file 
and lock that while the image is being generated if you need that 
feature.  It is perhaps 2 extra lines of code.
 [2009-12-04 00:34 UTC] rugkiks at gmail dot com
Yes, it isn't a big deal, and not breaking my workflow. But i believe 
file-locking is there for a reason, and is a neat feature making my 
code cleaner :).

Tons of programs solve this by having .lock files, so i guess this is 
also an understandable code.
 [2010-04-28 16:41 UTC]
-Summary: GD: imagepng doesn't doesn't have lockflags +Summary: GD: image* should work with stream handles -Package: Feature/Change Request +Package: *General Issues
 [2010-04-28 16:41 UTC]
Update the summary to reflect the necessary change, which is not about adding a locking mechanism in gd.
 [2010-04-28 16:44 UTC]
-Status: Assigned +Status: Duplicate
 [2010-04-28 16:44 UTC]
Duplicate of FR #39263.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 19 21:01:24 2021 UTC