Graham Conzett
Graham Conzett

Reputation: 8454

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?

Upvotes: 7

Views: 5514

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385088

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.

Upvotes: 10

Related Questions