簡體   English   中英

codeigniter file_get_content或curl在我們的開發服務器中不起作用

[英]codeigniter file_get_content or curl is not working in our dev server

需要獲取經度和緯度的位置詳細信息,它只能在其他服務器上工作-正常運行,但是嘗試使用客戶端開發服務器時出錯,我已經嘗試了大約4個小時-直到沒有得到結果。 協助會有所幫助。 這是我的代碼:

public function index() {
    echo $this->getLocation('39.2323', '-97.3828');
}

function getLocation($lat, $long) {
    $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . trim($lat) . "," . trim($long) . "&sensor=false";
    $json = @file_get_contents($url);
    $data = json_decode($json);
    $status = $data->status;
    $address = '';
    if ($status == "OK") {
        $address = $data->results[0]->formatted_address;
    }
    return $address;
}

正在收到如下錯誤:

遇到PHP錯誤嚴重性:警告消息:file_get_contents( http://maps.googleapis.com/maps/api/geocode/json?latlng=39.2323,-97.3828&sensor=false )[function.file-get-contents]:無法打開流:連接超時

文件名:webservice / Test.php行號:17

回溯:

文件:/home/colanful/public_html/hoa/application/controllers/webservice/Test.php行:17功能:file_get_contents

文件:/home/colanful/public_html/hoa/application/controllers/webservice/Test.php行:12功能:getaddress

文件:/home/colanful/public_html/hoa/index.php行:292功能:require_once

看來您需要在客戶端開發服務器上更改ini設置。

來自@Aillyn的答案:

您正在尋找的設置是allow_url_fopen。

您有兩種不更改php.ini的方法來解決它,一種是使用fsockopen(),另一種是使用cURL。

無論如何,我還是建議在file_get_contents()上使用cURL,因為它是為此而構建的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM