Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PHP's tmpfile() typically create the file in memory or on disk?

Tags:

file

php

I was curious about the behavior of tmpfile() and whether or not invoking it like

$temp = tmpfile();

Would create a file on disk or in memory. Perhaps it depends on the underlying system? In that case, is there a "more-often-than-not" case where most systems use one or the other?

like image 907
user49438 Avatar asked Oct 25 '25 14:10

user49438


1 Answers

The documentation implies that it would be created on disk, and specifically says to look for details in your system's implementation of tmpfile(3).

tmpfile(3) (on Linux) says Glibc will try the path prefix P_tmpdir defined in stdio.h, and if that fails the directory /tmp.

If you're looking for an in-memory temp file, perhaps you want php://temp.

like image 112
mkasberg Avatar answered Oct 27 '25 02:10

mkasberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!