On Sunday 07 May 2023 02:30:13 (+02:00), Dan Liebner wrote:
> > Why move the temporary file when it is already a temporary file,
right?
>
> If you don't want to have to write the file again with a copy?
Then why create a temporary file first? ^^
Nevertheless, a fair point it seems, and then thinking that this is what
often happens with tmpfile() on a Linux system:
- sys_get_temp_dir() is in the global file-system hierarchy and on a
file-system of its own (tmpfs)
- a move (rename) operation across file system boundaries is a copy &
delete operation
Given we're discussing file-system I/O to some extend here, and you're
asking what could possibly go wrong: A lot when we don't expect it and then
race conditions. Often we don't and even can't know in advance.
Therefore, if there is a need to create a temporary file in the first
place, do it. If not, don't create it, as otherwise you have the copy
already and this prevents you from learning if the file transaction really
needs it to become robust or it is just extra I/O for nothing (and perhaps
introduces places to error you actually don't want to deal with).
YMMV.
-- hakre
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php