如何测试 curl 在 PHP 中是否可用且没有错误

how to test if curl is available in PHP without errors

我正在尝试从命令行检测是否使用脚本 运行 中的 PHP 安装了 curl。我尝试了以下方法:

if(@function_exists('curl_version')){
...
}

error_reporting(E_ERROR);
ini_set('display_errors', '0');

if(is_callable('curl_init')){
...
}

但在这两种情况下我都收到此消息:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-zts-20121212/curl.so' - /usr/local/lib/php/extensions/no-debug-zts-20121212/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0

我希望隐藏错误消息,但 @ 和 error_reporting 似乎不起作用。是否有其他方法来抑制此消息?

你可以检查你安装的扩展

    $needed_extensions = array('curl',  '... other extionsions to check');
    $missing_extensions = array();
    foreach ($needed_extensions as $needed_extension) {
        if (!extension_loaded($needed_extension)) {
            $missing_extensions[] = $needed_extension;
        }
    }
    if (count($missing_extensions) > 0) {
        echo 'This software needs the following extensions, please install/enable them: ' . implode(', ', $missing_extensions) . PHP_EOL;
        exit(1);
    }

'