Skip to content

Commit

Permalink
Check disable_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Nov 8, 2024
1 parent 1f955a6 commit 5101b08
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,53 @@ protected static function checkSapiEnv(): void
{
// Only for cli and micro.
if (!in_array(PHP_SAPI, ['cli', 'micro'])) {
exit("Only run in command line mode\n");
exit("Only run in command line mode" . PHP_EOL);
}
// Check pcntl and posix extension for unix.
if (DIRECTORY_SEPARATOR === '/') {
foreach (['pcntl', 'posix'] as $name) {
if (!extension_loaded($name)) {
exit("Please install $name extension" . PHP_EOL);
}
}
}
// Check disable functions.
$disabledFunctions = explode(',', ini_get('disable_functions'));
$disabledFunctions = array_map('trim', $disabledFunctions);
$functionsToCheck = [
'stream_socket_server',
'stream_socket_accept',
'stream_socket_client',
'pcntl_signal_dispatch',
'pcntl_signal',
'pcntl_alarm',
'pcntl_fork',
'pcntl_wait',
'posix_getuid',
'posix_getpwuid',
'posix_kill',
'posix_setsid',
'posix_getpid',
'posix_getpwnam',
'posix_getgrnam',
'posix_getgid',
'posix_setgid',
'posix_initgroups',
'posix_setuid',
'posix_isatty',
'proc_open',
'proc_get_status',
'proc_close',
'shell_exec',
'exec',
'putenv',
'getenv',
];
$disabled = array_intersect($functionsToCheck, $disabledFunctions);
if (!empty($disabled)) {
$iniFilePath = (string)php_ini_loaded_file();
exit('Notice: '. implode(',', $disabled) . " are disabled by disable_functions. " . PHP_EOL
. "Please remove them from disable_functions in $iniFilePath" . PHP_EOL);
}
}

Expand Down

0 comments on commit 5101b08

Please sign in to comment.