1

I am trying to detect if curl is installed using PHP in a script run from the command line. I tried the following:

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

and

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

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

but in both cases I get this message:

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

I would prefer to hide the error message, but it appears that the @ and the error_reporting don't work. Is there a different way to suppress this message?

5
  • 1
    Possible duplicate of how to check if curl is enabled or disabled Commented Sep 13, 2016 at 13:11
  • 2
    Sounds like your issue is more to do with your configs still trying to reference the extension when it's not there. Note the PHP Startup.
    – Jonnix
    Commented Sep 13, 2016 at 13:12
  • 2
    As a good developer you never should prefere hiding errors, warnings etc. Combat the cause instead
    – B001ᛦ
    Commented Sep 13, 2016 at 13:13
  • 1
    if(function_exists('curl_init')){ /* go curling! */ }else{ /* we are experiencing technical difficulties, please try again later */ } will let you know if CURL is available but what's more important is that you hide all error messages from the user in a production system and log them. Review your error log weekly and fix any issues that arise.
    – MonkeyZeus
    Commented Sep 13, 2016 at 13:18
  • php -r 'echo function_exists("curl_init");'
    – simialbi
    Commented Sep 13, 2016 at 13:20

1 Answer 1

5

you could check your installed extionsions

    $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);
    }

'

2
  • I tried this and it correctly returned that the extension wasn't loaded, but the warning still appeared.
    – raphael75
    Commented Sep 13, 2016 at 17:38
  • 1
    is it possible, that you've actived the extension in the php.ini file but it doesn't exist on your hard disk?
    – mirko911
    Commented Sep 14, 2016 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.