File: gridfs-memory-usage-2.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (72 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--TEST--
GridFS: Testing memory usage
--SKIPIF--
<?php if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request'); ?>
<?php require_once "tests/utils/standalone.inc" ?>
--INI--
memory_limit=1G
--FILE--
<?php
require_once "tests/utils/server.inc";
$dsn = MongoShellServer::getStandaloneInfo();
$conn = new MongoClient($dsn);
$db   = $conn->selectDb('phpunit');
$grid = $db->getGridFs('wrapper');

// delete any previous results
$grid->drop();

// dummy file
$bytes = "";
for ($i=0; $i < 1024*1024; $i++) {
    $bytes .= sha1(rand(1, 1000000000));
}
$sha = sha1($bytes);
$grid->storeBytes($bytes, array("filename" => "demo.txt"), array('w' => true));

$memory = memory_get_usage();
echo $memory, "\n";
echo $memory > 40 * 1048576 ? "true" : "false", "\n";
echo $memory < 43 * 1048576 ? "true" : "false", "\n";
unset($bytes);

// fetch it
$file = $grid->findOne(array('filename' => 'demo.txt'));
$chunkSize = $file->file['chunkSize'];

// get file descriptor
$fp = $file->getResource();

$tmp = "";
$i=0;
while (!feof($fp)) {
	$s = 500000; // request 500k, but never more than 8192 is read
    $t = fread($fp, $s);
	$i += strlen($t);
}

$memory = memory_get_usage();
echo $memory, "\n";
echo $memory > 1 * 1048576 ? "true" : "false", "\n";
echo $memory < 4 * 1048576 ? "true" : "false", "\n";

$memory = memory_get_peak_usage();
echo $memory, "\n";
echo $memory > 40 * 1048576 ? "true" : "false", "\n";
echo $memory < 43 * 1048576 ? "true" : "false", "\n";


fclose($fp);
echo $i, "\n";
?>
--EXPECTF--
%d
true
true
%d
true
true
%d
true
true
41943040