cURL script working on localhost but not on live server

前端 未结 1 1937
醉话见心
醉话见心 2021-01-29 14:46

I am trying to send a SMS through script. I am using curl to run the API sending the SMS on the vendor server. fopen and file_get_contents are blocked on my server. So, cURL is

相关标签:
1条回答
  • 2021-01-29 15:01

    This is hard to say, but I would recommend adding CURLOPT_CONNECTTIMEOUT in addition to CURLOPT_TIMEOUT to your curl options. I am setting CURLOPT_CONNECTTIMEOUT to 5 in this example. And set CURLOPT_HTTPGET to TRUE. Also, adding CURLOPT_USERAGENT as well just in case the remote server needs something as a user agent:

    // Compose query
    $options = array(
    CURLOPT_URL => $adb_url.$uri."?".$query,
    CURLOPT_CUSTOMREQUEST => $method, // GET POST PUT PATCH DELETE HEAD OPTIONS 
    CURLOPT_POSTFIELDS => $json,
    CURLOPT_PORT => 8080,
    CURLOPT_HTTPGET => TRUE,
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",
    CURLOPT_HTTPHEADER => Array('Content-type: text/plain')
    ); 
    curl_setopt_array($adb_handle,($options + $adb_option_defaults)); 
    

    Also, unclear if the PHP version on your local setup is the same as the server.

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