PHP Curl does not work on localhost?

前端 未结 6 1552
既然无缘
既然无缘 2020-12-15 19:35

I am using MAMP Pro 1.9.4 on Mac OSX
In phpinfo() I see curl is enabled

cURL support    enabled
cURL Information    7.20.0
Age 3
Features
         


        
相关标签:
6条回答
  • 2020-12-15 20:04

    If you are behind a proxy, you could try adding CURLOPT_PROXY, for example (assuming your proxy is on 192.168.1.2 port 3128):

    $ch = curl_init($geocodeURL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXY, "192.168.1.2:3128");
    $result = curl_exec($ch);
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-15 20:10

    Do you actually have the curl binary installed? You can have the curl library installed with PHP without actually having the curl binary on your system. Drop to a shell prompt and type curl. (If it's standard on OSX then please forgive my ignorance - I'm not a Mac guy)

    0 讨论(0)
  • 2020-12-15 20:15

    It's not about proxy, it's about how to use googleapis.

    Add CURLOPT_SSL_ on your code and set them into false

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    
    0 讨论(0)
  • 2020-12-15 20:19

    It's probably a firewall issue. Curl by default tries to use port 1080, which is probably not open on your localhost / router / ISP.

    0 讨论(0)
  • 2020-12-15 20:21

    In MAMP, if you are getting errors when connecting to HTTPS hosts, just set this option:

    curl_setopt($ch, CURLOPT_SSLVERSION,3);

    The equivalent by command line is:

    curl -k -ssl3 https://www.your-secure-host.com

    0 讨论(0)
  • 2020-12-15 20:26

    You may need to set the SSL version and the matching Cipher for $ch:

    curl_setopt($ch, CURLOPT_SSLVERSION, 1);
    curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
    

    For the exact parameters you can pass to CURLOPT_SSLVERSION see: http://php.net/manual/en/function.curl-setopt.php

    Also the following can display errors related to SSL versions being used to help find exact version conflict you have:

    $error = curl_error($ch);
    echo $error;
    

    More on this command: http://php.net/manual/en/ref.curl.php

    0 讨论(0)
提交回复
热议问题