summaryrefslogtreecommitdiff
path: root/sapi/cli/tests/upload_2G.phpt
blob: a4bcc6860f716ed29ab4cf6fa5536299fe527c1d (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--TEST--
file upload greater than 2G
--SKIPIF--
<?php
include "skipif.inc";

if (PHP_INT_SIZE < 8) {
	die("skip need PHP_INT_SIZE>=8");
}

if ($f = fopen("/proc/meminfo","r")) {
	while (!feof($f)) {
		if (!strncmp($line = fgets($f), "MemFree", 7)) {
			if (substr($line,8)/1024/1024 > 3) {
				$enough_free_ram = true;
			}
		}
	}
}

if (empty($enough_free_ram)) {
	die("skip need +3G free RAM");
}

if (getenv('TRAVIS')) {
    die("skip Fails intermittently on travis");
}

if (getenv('SKIP_PERF_SENSITIVE')) {
    die("skip Test may be very slow if PHP is instrumented");
}
?>
--FILE--
<?php

echo "Test\n";

include "php_cli_server.inc";

php_cli_server_start("var_dump(\$_FILES);", false,
	"-d post_max_size=3G -d upload_max_filesize=3G");

list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port)?:80;
$length = 2150000000;
$output = "";

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
  die("connect failed");
}

$prev = "----123
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name=\"file1\"; filename=\"file1.txt\"\n\n";
$post = "\n----123--\n";
$total = $length + strlen($prev) + strlen($post);

fwrite($fp, <<<EOF
POST /index.php HTTP/1.1
Host: {$host}
Content-Type: multipart/form-data; boundary=--123
Content-Length: {$total}

{$prev}
EOF
) or die("write prev failed");

$data = str_repeat("0123456789", 10000);
for ($i = 0; $i < $length; $i += 10000 * 10) {
	fwrite($fp, $data) or die("write failed @ ($i)");
}

fwrite($fp, $post) or die("write post failed");

while (!feof($fp)) {
	$output .= fgets($fp);
}
echo $output;
fclose($fp);
?>
Done
--EXPECTF--
Test
HTTP/1.1 200 OK
Host: %s
Date: %s
Connection: close
X-Powered-By: PHP/%s
Content-type: text/html; charset=UTF-8

array(1) {
  ["file1"]=>
  array(5) {
    ["name"]=>
    string(9) "file1.txt"
    ["type"]=>
    string(10) "text/plain"
    ["tmp_name"]=>
    string(%d) "%s"
    ["error"]=>
    int(0)
    ["size"]=>
    int(2150000000)
  }
}
Done