Skip to content

Commit ee59a4f

Browse files
authored
fix: php warnings in restricted environments (#4336)
1 parent 66c84e4 commit ee59a4f

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

framework/core/src/Foundation/Console/InfoCommand.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function detectWebServerPhpVersion(): ?string
192192
];
193193

194194
foreach ($possiblePhpBinaries as $phpBinary) {
195-
if (file_exists($phpBinary) && is_executable($phpBinary)) {
195+
if (@file_exists($phpBinary) && @is_executable($phpBinary)) {
196196
$output = [];
197197
$status = null;
198198
exec("$phpBinary -v 2>&1 | head -n 1", $output, $status);
@@ -234,30 +234,30 @@ private function detectWebServerMemoryLimit(): ?string
234234
];
235235

236236
foreach ($possiblePaths as $path) {
237-
if (file_exists($path) && is_readable($path)) {
238-
$content = file_get_contents($path);
237+
if (@file_exists($path) && @is_readable($path)) {
238+
$content = @file_get_contents($path);
239239

240240
// Look for memory_limit setting
241-
if (preg_match('/^\s*memory_limit\s*=\s*(.+?)\s*$/m', $content, $matches)) {
241+
if ($content && preg_match('/^\s*memory_limit\s*=\s*(.+?)\s*$/m', $content, $matches)) {
242242
return trim($matches[1]);
243243
}
244244

245245
// For FPM pool configs, also check php_admin_value
246-
if (preg_match('/^\s*php_admin_value\[memory_limit\]\s*=\s*(.+?)\s*$/m', $content, $matches)) {
246+
if ($content && preg_match('/^\s*php_admin_value\[memory_limit\]\s*=\s*(.+?)\s*$/m', $content, $matches)) {
247247
return trim($matches[1]);
248248
}
249249
}
250250
}
251251

252252
// Also scan /usr/local/etc/php/conf.d/ directory for any INI files with memory_limit
253253
$confDir = '/usr/local/etc/php/conf.d';
254-
if (is_dir($confDir) && is_readable($confDir)) {
255-
$iniFiles = glob($confDir . '/*.ini');
254+
if (@is_dir($confDir) && @is_readable($confDir)) {
255+
$iniFiles = @glob($confDir . '/*.ini');
256256
if ($iniFiles) {
257257
foreach ($iniFiles as $iniFile) {
258-
if (is_readable($iniFile)) {
259-
$content = file_get_contents($iniFile);
260-
if (preg_match('/^\s*memory_limit\s*=\s*(.+?)\s*$/m', $content, $matches)) {
258+
if (@is_readable($iniFile)) {
259+
$content = @file_get_contents($iniFile);
260+
if ($content && preg_match('/^\s*memory_limit\s*=\s*(.+?)\s*$/m', $content, $matches)) {
261261
return trim($matches[1]);
262262
}
263263
}

0 commit comments

Comments
 (0)