2016-05-05 8 views
0

誰でもこれで私を助けてくれることを願っています。私はcURLを使用して外部サイトを呼び出そうとしましたが、エラーまたは応答はありません。ただし、ローカルサーバーでは正常に動作しますが、運用サーバーでは動作しません。私はfile_get_contents()を使って呼び出しを開始しましたが、オンラインでも失敗しました。私はホスティングと話をし、問題はコード内にあると述べた。ここに私のコードは、私はまたのfile_get_contentsを使用する別の関数を()持っていると私は、彼らがローカルに動作しますが、エラーなしでオンラインに失敗使用することができますどちら私が修正しようと4時間以上を費やし、誰でも助けることができる!? `cURL geto no noオンラインサーバエラーなし

function send_with_curl($url, $data) { 
    $data_string; 
     //url-ify the data for the POST 
    foreach ($data as $key => $value) { $data_string .= $key . '=' . $value . '&'; 
} 
rtrim($data_string, '&'); 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 60); 
curl_setopt($ch, CURLOPT_POST, count($data)); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 

//execute post 
$result = curl_exec($ch); 
if (!is_string($result) || !strlen($result)) {  
    $result = "Failed to connect."; 
} 
//close connection 
curl_close($ch); 
return $result; 
} 

です彼らは最終的にエラーがコード内にあると、彼らはこれらのコードに精通していなかったまで人をホスティング:(

function send_with_file($url, $context, $sender) { 
global $database; 
if (!$result = file_get_contents($url, false, $context)) { 
    echo "Message sending failed, please check your internet."; 
    exit ; 
} else { 
    //--UPDATING THE DATABASE------ 
    $sql_update = "SELECT * FROM users WHERE users_type='2'"; 
    $query_update = $database -> query($sql_update); 
    while ($update = $database -> fetch_array($query_update)) { 
     $update_user = $update['users_id']; 
     if ($update_user == $sender) { 

      if ($result === FALSE) {/* Handle error */ 
      } 
     } else { 

     } 

    } 
} 
return $result; 
} 

答えて

0

コードに問題はありませんでしたが、私はちょうど私がに接続しようとしていたURLを追跡し、それがホスティングサーバーとの通信に時間がかかりすぎる実現しました。

0

とそれfalseに対して$resultを比較して、curl_error()

いくつかをご確認ください事のように...

$result = curl_exec($ch); 
if($result === false) { 
    echo "Error in cURL : " . curl_error($ch); 
} 
+0

それは何の応答も出さない! : '( –

+0

URLは実際に何かを返していますか? – Dale

+0

私のローカルサーバー上でURLからの応答が得られますが、プロダクションサーバーでは何も得られず、要求を実行できません。 –