Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is php://temp safe for production?

I have a scenario in which I want to re-use an existing class to compile changes in the system. The existing libraries take a file pointer that will store the changes for subsequent use. The current scenario involves performing those calculations and then immediately outputting the response to output.

Would it be safe to use the php://temp or php://memory resources in an environment where it is possible that two separate users will run this method at the same time?

Pseudo-code:

$fp = fopen('php://temp','w+');
Lib::getUpdates($fp, $user_id);
rewind($fp);
$changes = stream_get_contents($fp);

I have been googling around and have found some unsettling results but nothing really definitive about using the temp or memory streams.

So the question is, should I just break down and use a temporary file that will guarantee this isn't a problem? I would like to avoid writing to disk if possible. The other possibility is to alter the class so that it can output the results to a string, but I'd like to avoid that if possible as well.

EDIT

According to Sammitch, this is ok. See comments below.

like image 712
Rhinosaurus Avatar asked Sep 23 '13 18:09

Rhinosaurus


1 Answers

php://temp and php://memory are unique per-process. You do not have to worry about two processes attempting to use the same memory at the same time.

like image 95
Sammitch Avatar answered Oct 04 '22 11:10

Sammitch