ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PhpServerConfiguration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 // — PHP runtime —
31
32 public function getPhpVersion(): string
33 {
34 return PHP_VERSION;
35 }
36
37 public function getPhpSapi(): string
38 {
39 return PHP_SAPI;
40 }
41
42 public function isFpm(): bool
43 {
44 return PHP_SAPI === 'fpm-fcgi';
45 }
46
47 public function getPhpBinary(): string
48 {
49 if (PHP_BINARY !== '') {
50 return escapeshellarg(PHP_BINARY);
51 }
52
53 foreach ([PHP_BINDIR . '/php', PHP_BINDIR . '/php-cli.exe', PHP_BINDIR . '/php.exe'] as $candidate) {
54 if (is_readable($candidate)) {
55 return escapeshellarg($candidate);
56 }
57 }
58
59 return 'php';
60 }
61
62 // — Error handling —
63
64 public function getErrorReportingLevel(): int
65 {
66 return (int) ini_get('error_reporting');
67 }
68
69 public function isErrorLoggingEnabled(): bool
70 {
71 return filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN);
72 }
73
74 public function isErrorDisplayEnabled(): bool
75 {
76 return filter_var(ini_get('display_errors'), FILTER_VALIDATE_BOOLEAN);
77 }
78
79 // — Memory & upload limits —
80
81 public function getMemoryLimit(): DataSize
82 {
83 return new DataSize($this->parseIniBytes(ini_get('memory_limit')), DataSize::Byte);
84 }
85
86 public function getUploadSizeLimit(): DataSize
87 {
88 $bytes = min(
89 $this->parseIniBytes(ini_get('post_max_size')),
90 $this->parseIniBytes(ini_get('upload_max_filesize')),
91 );
92 return new DataSize($bytes, DataSize::Byte);
93 }
94
95 public function getPostMaxSize(): DataSize
96 {
97 return new DataSize($this->parseIniBytes(ini_get('post_max_size')), DataSize::Byte);
98 }
99
101 {
102 return new DataSize($this->parseIniBytes(ini_get('upload_max_filesize')), DataSize::Byte);
103 }
104
105 // — Execution constraints —
106
107 public function getMaxExecutionTime(): int
108 {
109 return (int) ini_get('max_execution_time');
110 }
111
112 public function getMaxInputVars(): int
113 {
114 return (int) ini_get('max_input_vars');
115 }
116
117 // — Operating system —
118
119 public function getOperatingSystem(): string
120 {
121 return PHP_OS;
122 }
123
124 public function getOperatingSystemFamily(): string
125 {
126 return PHP_OS_FAMILY;
127 }
128
129 // — Internal —
130
131 private function parseIniBytes(string $value): int
132 {
133 if (is_numeric($value)) {
134 return (int) $value;
135 }
136
137 $suffix = strtoupper(substr($value, -1));
138 $number = (int) substr($value, 0, -1);
139
140 return match ($suffix) {
141 'P' => $number * 1024 ** 5,
142 'T' => $number * 1024 ** 4,
143 'G' => $number * 1024 ** 3,
144 'M' => $number * 1024 ** 2,
145 'K' => $number * 1024,
146 default => (int) $value,
147 };
148 }
149}
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
getUploadSizeLimit()
Effective upload size limit: min(post_max_size, upload_max_filesize).
getPhpBinary()
Returns the escaped path to the PHP CLI binary.
Read access to PHP runtime and server configuration.