0
我处理的一个问题,即从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
它只是等待一些东西,直到时间结束。
你有什么建议吗?
您可以使用ini_set('max_execution_time',180);(3分钟)增加最大执行时间。但试着在网络选项卡下的chrome控制台中跟踪问题,看看你是否具有较高的TTFB或下载时间。如果等待是因为下载,请启用gzip压缩。 –
我第二个Nikolay的评论,如果这个其他服务器是你的,在HTTP上启用GZIP压缩可以产生巨大的差异,比如高达10:1的改进。 – TravisO