Voting

: max(one, seven)?
(Example: nine)

The Note You're Voting On

nguyenanthuan at gmail dot com
9 years ago
Each stream pointer to php://memory and php://temp has its own memory allocation, so you can open many stream pointers to store your separated values.

<?php
$fp
= fopen("php://temp", "r+");
$fp2 = fopen("php://temp", "r+");

fwrite($fp, "line1\n");
fwrite($fp2, "line4\n");
fwrite($fp, "line2\n");
fwrite($fp2, "line5\n");
fwrite($fp, "line3\n");
fwrite($fp2, "line6\n");

var_dump(memory_get_usage());

rewind($fp);
while(!
feof($fp)) {
var_dump(fread($fp, 1024));
}
fclose($fp);
var_dump(memory_get_usage());

rewind($fp2);
while(!
feof($fp2)) {
var_dump(fread($fp2, 1024));
}
fclose($fp2);
var_dump(memory_get_usage());
?>

Closing their stream handles will also free the allocated memory.

php://memory stream type is MEMORY, while php://temp stream type is STDIO FILE*.

<< Back to user notes page

To Top