I write simple requirements checking script. It checks all required PHP modules installed. I need to check if pcntl is installed. But this module is accessible only in cgi environment and invisible for web queries. extension_loaded('pcntl') and function_exists('pcntl_fork') both return false. How can I perform this check?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Create a file called cli_supports.php
<?php
$supports = array();
if (function_exists("pcntl_fork")) $supports[] = "pcntl";
echo implode(",", $supports);
?>
Then from your feature detection scripts do.
$cli_features = explode(",", shell_exec("/usr/local/bin/php ".escapeshellarg(_DIR_."/cli_supports.php")));
回答2:
If it is installed, the code bellow returns true
var_dump (extension_loaded('pcntl'));
回答3:
Running php -i | grep pcntl
will return the following if pcntl is enabled.
pcntl
pcntl support => enabled
回答4:
If you're sure it's supported (or shared object exists) then check your php.ini and make sure it's loaded as an extension.
extension_loaded()
should work (and what I prefer over function_exists()
), and the only reason I can imagine it wouldn't is you not loading the shared object.