[RFC] Modify tempnam() to handle directories and auto-cleanup

php.internals

Sara Golemon

13 years ago
https://wiki.php.net/rfc/request-tempnam Just a bit of hand-holding for those who don't remember to clean up their messes.

Johannes Schlueter

13 years ago
Hi, On Mon, 2012-11-26 at 13:21 -0800, Sara Golemon wrote:
> https://wiki.php.net/rfc/request-tempnam > > Just a bit of hand-holding for those who don't remember to clean up > their messes.
An obvious question is: When in shutdown should that be called? Assume I have a session handler which uses such a temporary directory which is backed by a custom stream while having a registered shutdown function accessing that session (what did i forget to put into that scenario?) johannes

Sara Golemon

13 years ago
> An obvious question is: When in shutdown should that be called? Assume I > have a session handler which uses such a temporary directory which is > backed by a custom stream while having a registered shutdown function > accessing that session (what did i forget to put into that scenario?) >
Is this custom session handler wanting the temporary directory to last between requests? If so then they'd just not use the TEMPNAM_REQUEST flag. If not, then there wouldn't be a problem since RSHUTDOWN happens after calling the methods registered with register_shutdown_function(). -Sara

Lars Strojny

13 years ago
Good idea! Am 26.11.2012 um 22:21 schrieb Sara Golemon <pollita@php.net>:

Sherif Ramadan

13 years ago
On Mon, Nov 26, 2012 at 4:21 PM, Sara Golemon <pollita@php.net> wrote:
> https://wiki.php.net/rfc/request-tempnam > > Just a bit of hand-holding for those who don't remember to clean up > their messes. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
While I don't think there's anything wrong with this feature, I'm also wondering if maybe people that need this should be using tmpfile() instead? I understand they do slightly different things (in that one gives you an actual file name the other gives you a file handle), but I normally don't need or care about the file name if I expect my temporary file to live and die with the request. Things I usually use tempnam() for are usually things that get born with the request and don't necessarily die with it, like binary storage that's tied to the session (temporary file uploads that might be moved later or deleted). But I don't see any harm in adding this either.

Keisial

13 years ago
On 26/11/12 22:21, Sara Golemon wrote:
> https://wiki.php.net/rfc/request-tempnam > > Just a bit of hand-holding for those who don't remember to clean up > their messes.
I like it. Also note that it's not always that people “don't remember to clean up their messes” since there are several tricky cases: client closed the connection before the unlink, an exception was thrown... OTOH it may make harder when you actually want to stop an script and inspect it's temp files :)