From 21f6a4b4258e59c373a0a11f2e4d207c9ae61c56 Mon Sep 17 00:00:00 2001 From: wojciechem Date: Wed, 14 Sep 2022 21:18:54 +0200 Subject: [PATCH] fix: check that required extensions are enabled. Resolves #1 It displays (hopefully) informative message about missing extensions when pcntl / mbstring functions are not defined --- h-m-m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/h-m-m b/h-m-m index 6c1ae26..ddb8987 100755 --- a/h-m-m +++ b/h-m-m @@ -149,6 +149,10 @@ function shutdown() exit; } +if (false === check_required_extensions()) { + return 1; +} + register_shutdown_function("shutdown"); declare(ticks = 1); pcntl_signal(SIGINT,"shutdown"); @@ -2420,6 +2424,23 @@ function monitor_key_presses(&$mm) } } +function check_required_extensions(): bool +{ + if (!function_exists('pcntl_signal')) { + echo 'Required extension pcntl is not enabled; please check your php installation!'; + echo PHP_EOL; + return false; + } + + if (!function_exists('mb_strlen')) { + echo 'Required extension mbstring is not enabled; please check your php installation!'; + echo PHP_EOL; + return false; + } + + return true; +} + // }}} // {{{ main