-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample-04.php
38 lines (25 loc) · 919 Bytes
/
example-04.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// store in memory until it becomes scare
print "mem limit: ".ini_get("memory_limit")."\n";
#$membuffer = 10 * 1024 * 1024;
#$membuffer = 50 * 1024 * 1024;
#$membuffer = 100 * 1024 * 1024;
$membuffer = 54 * 1024 * 1024;
$fp = fopen("php://temp/maxmemory:$membuffer", "rw+");
#$fp = fopen("php://temp/", "rw+");
/*
Maximum amount of data to keep in memory before using a temporary file, in bytes.
Default = 2mb
*/
$bp = fopen("bacon-ipsum.txt", "r");
#$bp = fopen("bacon-ipsum-small.txt", "r");
print "peak use: ".round(memory_get_peak_usage()/1048576,2)."M\n";
fputs($fp, stream_get_contents($bp));
print "peak use: ".round(memory_get_peak_usage()/1048576,2)."M\n";
rewind($fp);
print "[".str_word_count(stream_get_contents($fp))."]\n";
fclose($fp);
fclose($bp);
print "mem usage: ".round(memory_get_usage()/1048576,2)."M\n";
print "peak use : ".round(memory_get_peak_usage()/1048576,2)."M\n";
?>