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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With