Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory mapped files in PHP, what is the difference between php://temp and php://memory

I am in need of a way to store a file in memory very briefly in PHP, the file is being built and then sent right off to another web service. I see that as of PHP 5.1 the php://temp and php://memory streams are available, but there doesn't seem to be a whole lot of difference between the two: php://temp supports the stream_select() function and php://memory does not. Which one should I be using in this case, or is there a better way to do memory mapped files in PHP?

like image 941
Graham Conzett Avatar asked May 14 '11 23:05

Graham Conzett


1 Answers

Straight out of the relevant manual page:

The php://memory wrapper stores the data in the memory. php://temp behaves similarly, but uses a temporary file for storing the data when a certain memory limit is reached (the default is 2 MB).

Source: I went on Google and searched for php temp memory. This was the first result, with the answer in the extract.

php://temp sounds appropriate for your use case.

like image 142
Lightness Races in Orbit Avatar answered Nov 02 '22 13:11

Lightness Races in Orbit