@@ -9,26 +9,36 @@ if (PHP_INT_SIZE < 5) {
9
9
if (getenv ('SKIP_SLOW_TESTS ' )) {
10
10
die ('skip slow test ' );
11
11
}
12
- function get_system_memory ( ): int | float | false
12
+ function has_enough_memory ( int $ bytes ): bool
13
13
{
14
14
if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
15
15
// Windows-based memory check
16
16
@exec ('wmic OS get FreePhysicalMemory ' , $ output );
17
17
if (isset ($ output [1 ])) {
18
- return ((int )trim ($ output [1 ])) * 1024 ;
18
+ return ((( int )trim ($ output [1 ])) * 1024 ) >= $ bytes ;
19
19
}
20
20
} else {
21
+ // cgroup v1
22
+ $ limit = @file_get_contents ('/sys/fs/cgroup/memory/memory.limit_in_bytes ' );
23
+ if ($ limit && (int )$ limit < $ bytes ) {
24
+ return false ;
25
+ }
26
+ // cgroup v2
27
+ $ limit = @file_get_contents ('/sys/fs/cgroup/memory.max ' );
28
+ if ($ limit && !str_contains ($ limit , 'max ' ) && (int )$ limit < $ bytes ) {
29
+ return false ;
30
+ }
21
31
// Unix/Linux-based memory check
22
32
$ memInfo = @file_get_contents ("/proc/meminfo " );
23
33
if ($ memInfo ) {
24
34
preg_match ('/MemFree:\s+(\d+) kB/ ' , $ memInfo , $ matches );
25
- return $ matches [1 ] * 1024 ; // Convert to bytes
35
+ return ( $ matches [1 ] * 1024 ) >= $ bytes ; // Convert to bytes
26
36
}
27
37
}
28
38
return false ;
29
39
}
30
- if ( get_system_memory () < 10 * 1024 * 1024 * 1024 ) {
31
- die ('skip Reason: Insufficient RAM (less than 10GB) ' );
40
+ if (! has_enough_memory ( 10 * 1024 * 1024 * 1024 )) { // 10GB
41
+ die ('skip Reason: Insufficient RAM (should be 10GB) ' );
32
42
}
33
43
$ tmpfile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin " ;
34
44
$ tmpfileh = fopen ($ tmpfile , "wb " );
0 commit comments