xref: /PHP-8.2/sapi/cli/tests/upload_2G.phpt (revision e1ec67ac)
1--TEST--
2file upload greater than 2G
3--SKIPIF--
4<?php
5include "skipif.inc";
6
7if (PHP_INT_SIZE < 8) {
8    die("skip need PHP_INT_SIZE>=8");
9}
10
11if (disk_free_space(sys_get_temp_dir()) < 2300000000) {
12    die("skip need more than 2.15G of free disk space for the uploaded file");
13}
14
15if (!file_exists('/proc/meminfo')) {
16    die('skip Cannot check free RAM from /proc/meminfo on this platform');
17}
18
19$free_ram = 0;
20if ($f = fopen("/proc/meminfo","r")) {
21    while (!feof($f)) {
22        if (preg_match('/MemFree[^\d]*(\d+)/i', fgets($f), $m)) {
23            $free_ram = max($free_ram, $m[1]/1024/1024);
24            if ($free_ram > 3) {
25                $enough_free_ram = true;
26            }
27        }
28    }
29}
30
31if (empty($enough_free_ram)) {
32    die(sprintf("skip need +3G free RAM, but only %01.2f available", $free_ram));
33}
34
35if (getenv('TRAVIS')) {
36    die("skip Fails intermittently on travis");
37}
38
39if (getenv('CIRRUS_CI')) die('skip Fails on Cirrus');
40
41if (getenv('SKIP_PERF_SENSITIVE')) {
42    die("skip Test may be very slow if PHP is instrumented");
43}
44?>
45--CONFLICTS--
46all
47--FILE--
48<?php
49
50echo "Test\n";
51
52include "php_cli_server.inc";
53
54php_cli_server_start("var_dump(\$_FILES);", null,
55    ["-d", "post_max_size=3G", "-d", "upload_max_filesize=3G"]);
56
57$length = 2150000000;
58$output = "";
59
60$host = PHP_CLI_SERVER_HOSTNAME;
61$fp = php_cli_server_connect();
62
63$prev = "----123
64Content-Type: text/plain; charset=UTF-8
65Content-Disposition: form-data; name=\"file1\"; filename=\"file1.txt\"\n\n";
66$post = "\n----123--\n";
67$total = $length + strlen($prev) + strlen($post);
68
69fwrite($fp, <<<EOF
70POST /index.php HTTP/1.1
71Host: {$host}
72Content-Type: multipart/form-data; boundary=--123
73Content-Length: {$total}
74
75{$prev}
76EOF
77) or die("write prev failed");
78
79$data = str_repeat("0123456789", 10000);
80for ($i = 0; $i < $length; $i += 10000 * 10) {
81    fwrite($fp, $data) or die("write failed @ ($i)");
82}
83
84fwrite($fp, $post) or die("write post failed");
85
86while (!feof($fp)) {
87    $output .= fgets($fp);
88}
89echo $output;
90fclose($fp);
91?>
92Done
93--EXPECTF--
94Test
95HTTP/1.1 200 OK
96Host: %s
97Date: %s
98Connection: close
99X-Powered-By: PHP/%s
100Content-type: text/html; charset=UTF-8
101
102array(1) {
103  ["file1"]=>
104  array(6) {
105    ["name"]=>
106    string(9) "file1.txt"
107    ["full_path"]=>
108    string(9) "file1.txt"
109    ["type"]=>
110    string(10) "text/plain"
111    ["tmp_name"]=>
112    string(%d) "%s"
113    ["error"]=>
114    int(0)
115    ["size"]=>
116    int(2150000000)
117  }
118}
119Done
120