简体   繁体   中英

PHP: Module 'curl' already loaded

I'm trying to do a curl POST request in CLI, and it throw this exception :

PHP Warning:  Module 'curl' already loaded in Unknown on line 0

This script works perfectly in local environment (mac os) but when i put it in production (ubuntu 16.04), it throws this exception.

I'm using PHP 5.6 version.

Here is the PHP method :

function post_request($url, $data){
    $fields_string =http_build_query($data);
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
    $result = curl_exec($ch);
    curl_close($ch);

    return $result;
}

For information my method is used in the same project (not in cli mode) and works like a charm. the bug is thrown only in CLI mode.

when i look in /etc/php/5.6/php.ini , the curl module is only loaded once.

Any Idea ?

There are 2 sets of config points which may be causing the problem. You have the php.ini and then you have the directory of config files - conf.d.

Your conf.d file for curl is (for php5.6 cli) - /etc/php/5.6/cli/conf.d/20-curl.ini.

The rationale seams to be that the conf.d directory may be linked so that all the environments can use the same configuration, but your php.ini can contain a specific configuration for the (for example) CLI version of PHP.

If you want curl to be available and configured the same in all environments, then best to comment out any config parts in the php.ini.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM