Laravel 5 使用文件获取内容()时发生Laravel错误异常

Laravel 5 使用文件获取内容()时发生Laravel错误异常,laravel-5,Laravel 5,大家好,我是拉威尔的新手,我有这个错误。我真的不知道这是什么,所以我希望有人能帮我解决它 E/errror: { "message": "file_get_contents(https://maps.googleapis.com/maps/api/directions/json?origin=**.89**9029,**.8584**5&destination=**.897**1522708,**.858512**80171&mode=driving&am

大家好,我是拉威尔的新手,我有这个错误。我真的不知道这是什么,所以我希望有人能帮我解决它

E/errror: {
    "message": "file_get_contents(https://maps.googleapis.com/maps/api/directions/json?origin=**.89**9029,**.8584**5&destination=**.897**1522708,**.858512**80171&mode=driving&key=**********): failed to open stream: Connection timed out",
    "exception": "ErrorException",
    "file": "/home/**/domains/**.tech/app/Http/Controllers/Helper/GoogleController.php",
    "line": 99,
    "trace": [
        {
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/app/Http/Controllers/Helper/GoogleController.php",
            "line": 99,
            "function": "file_get_contents"
        },
        {
            "file": "/home/**/domains/**.tech/app/Http/Controllers/Api/BookingController.php",
            "line": 1854,
            "function": "GoogleDistanceAndTime",
            "class": "App\\Http\\Controllers\\Helper\\GoogleController",
            "type": "::"
        },
        {
            "file": "/home/**/domains/**.tech/app/Http/Controllers/Api/BookingController.php",
            "line": 1831,
            "function": "EtaCalculation",
            "class": "App\\Http\\Controllers\\Api\\BookingController",
            "type": "->"
        },
        {
            "function": "Tracking",
            "class": "App\\Http\\Controllers\\Api\\BookingController",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 219,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 176,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 680,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/app/Http/Middleware/ValidUser.php",
            "line": 25,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 163,
            "function": "handle",
            "class": "App\\Http\\Middleware\\ValidUser",
            "type": "->"
        },
        {
            "file": "/home/**/domains/**.tech/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type
responseFromServerError
这是laravel内部的功能:

App/Http/Controllers/Helper/GoogleController.php

我真的迷路了不知道发生了什么

public static function GoogleDistanceAndTime($from, $to, $key)
{
    $data = file_get_contents("https://maps.googleapis.com/maps/api/directions/json?origin=$from&destination=$to&mode=driving&key=$key");
    $data = json_decode($data, true);
    $status = $data['status'];
    if ($status != "OK") {
        return array('time' => "", 'distance' => "");
    } else {
        $time = $data['routes'][0]['legs'][0]['duration']['text'];
        $distance = $data['routes'][0]['legs'][0]['distance']['text'];
        return array('time' => $time, 'distance' => $distance);
    }
}

让我给你看你需要的东西。谢谢

查看有关此堆栈溢出问题答案的评论:

很可能在php安装中禁用了fopen包装器,您应该使用
curl\u exec
来调用该服务。有关在php中使用curl功能的信息如下:


如果你使用LaaFLE,你也可以考虑在Laravel中使用一个包,再次,检查这个堆栈溢出问题的选项,这样做:

看看这个堆栈溢出问题的答案:

很可能在php安装中禁用了fopen包装器,您应该使用
curl\u exec
来调用该服务。有关在php中使用curl功能的信息如下:

如果你使用LaaFLE,你也可以考虑在Laravel中使用一个包,再次,检查这个堆栈溢出问题的选项,这样做:< /P>