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

- Thread: https://externals.io/message/64054
- Original archive: https://news-web.php.net/php.internals/64054
- Started by Sara Golemon on 2012-11-26T21:21:55+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #64054 — Sara Golemon — 2012-11-26T21:21:55+00:00

URL: https://externals.io/message/64054#64054

https://wiki.php.net/rfc/request-tempnam

Just a bit of hand-holding for those who don't remember to clean up
their messes.

---

## #64055 — johannes@schlueters.de — 2012-11-26T23:11:10+00:00

URL: https://externals.io/message/64054#64055 · In reply to: #64054

Hi,


> 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

---

## #64056 — Sara Golemon — 2012-11-27T00:30:23+00:00

URL: https://externals.io/message/64054#64056 · In reply to: #64055

> 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

---

## #64063 — Lars Strojny — 2012-11-27T09:12:12+00:00

URL: https://externals.io/message/64054#64063 · In reply to: #64054

Good idea!

Am 26.11.2012 um 22:21 schrieb Sara Golemon <pollita@php.net>:

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

---

## #64064 — Sherif Ramadan — 2012-11-27T17:08:24+00:00

URL: https://externals.io/message/64054#64064 · In reply to: #64054

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

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.
