仅在第二次

时间:2017-01-26 13:32:49

标签: php json

我正在处理一个问题,我从第二次使用的url(在我的情况下是JSON文件)回答是需要一段时间,所以php返回我

Fatal error: Maximum execution time of 30 seconds exceeded in [myfile] on line 54

以下是一些代码:

save_road.php

<?php    
include('simple_html_dom.php');
include('controller.php');
$restrictions = new road_restrictions; ?>

Controller.php这样

include('functions-map.php');

class road_restrictions {

    function __construct() {
        $road_id = get_road_id();
        show($road_id);
        $informacion = $this->get_all_info($road_id);  //goes here

        foreach ($informacion as $info) {
            $this->save($info);
        }

        //show($informacion);
    }

    function get_all_info($road_id) {

        foreach ($road_id as $id) {
            $road_info = get_info($id);   //goes here

            if ($road_info !== NULL) {
                $info[] = $road_info;
            }
        }
        return $info;
    }

    function save($info) {
        save_road($info);
    }
}

功能-map.php

function get_info($id) {                
$json = file_get_contents('http://restrictions.eismoinfo.lt/');  //stuck here
$array = json_decode($json, true);
//other code

在代码的这一点上花费太多时间。第一次调用它时 functions-map.php 函数get_road_id()(获取json的代码相同)它工作得很好,但是当涉及get_info时函数file_get_contents只是等待时间结束。

你有什么建议吗?

1 个答案:

答案 0 :(得分:1)

尝试从php.ini文件中增加 max_execution_time

OR

在执行get_info()之前添加此行;功能 set_time_limit(60);