我有一个充满XML文件的目录。对于这些文件中的每一个,我都在RIPE进行搜索。对于每次搜索,我都会通过返回的HTML代码进行几次RegEx搜索。但经过几次循环后,file_get_contents会停止返回数据,之后的所有操作都会在空字符串上完成。
我认为PHP可能会超时,因为这些页面需要一段时间才能加载。但是脚本执行不会完全停止吗?相反,所有循环都完成并输出他们的HTML代码,但没有内容。
我也猜测可能存在某种最大请求,第二次处理PHP。
这里的任何人都可以对此有所了解吗?
由于
编辑:为了解释我的标题,我的一个朋友和我自己同时运行该脚本。这就是为什么我猜测PHP会限制它可以发送多少分钟或者什么的请求,因为看起来PHP在它停止返回数据之前管理了不同数量的循环。
编辑:添加了一些代码:(我认为不需要,因为我对问题的解释)
<?php
set_time_limit(0);
include "pagebase.php";
$page = new pagebase();
$page->jQuery = true;
$page->formatDoc = false;
$page->addScript("javascript.js");
$page->addStylesheet("../codeclean.css");
$page->addStylesheet("stylesheet.css");
$page->title = "...";
$directory_path = "xml_documents";
$directory = scandir($directory_path);
$files = array();
foreach($directory as $string)
{
if(preg_match("/.*\.xml/", $string, $result) > 0)
array_push($files, $result[0]);
}
$content =
"
<table cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td colspan=\"7\">
<center><h2>...</h2></center>
</td>
</tr>
<tr>
<td class=\"header_cell\">Case ID</td>
<td class=\"header_cell\">Description (From RIPE)</td>
<td class=\"header_cell\">IP</td>
<td class=\"header_cell\">Fil</td>
<td class=\"header_cell\">Time</td>
<td class=\"header_cell\">Type</td>
</tr>
";
foreach($files as $index => $file)
{
$xml = simplexml_load_file("$directory_path/$file");
$id = trim($xml->Case->ID);
$ip = trim($xml->Source->IP_Address);
$title = trim($xml->Content->Item->Title);
$time = trim($xml->Source->TimeStamp);
$type = trim($xml->Source->Type);
$desc_result = array();
$info_result = array();
$RIPE_result = file_get_contents("http://www.db.ripe.net/whois?searchtext=$ip");
preg_match("/(?<=descr:)(\s*)(.*)/", $RIPE_result, $desc_result);
preg_match_all("/<pre>.*<\/pre>/sm", $RIPE_result, $info_result);
$info_result[0] = implode("", $info_result[0]);
if(count($desc_result) < 1) $desc_result[0] = "<font style=\"color:red\">No description found</font>";
else $desc_result[0] = trim($desc_result[0]);
$content .=
"
<tr id=\"info_row_$index\">
<td class=\"info_cell\">$id</td>
<td class=\"info_cell\">$desc_result[0]</td>
<td class=\"info_cell\">$ip</td>
<td class=\"info_cell\">$title</td>
<td class=\"info_cell\">$time</td>
<td class=\"info_cell\">$type</td>
</tr>
<tr id=\"expanded_row_$index\">
<td class=\"expanded_cell\" colspan=\"7\">
<div id=\"content_container_$index\">
<input type=\"button\" class=\"pastey_button\" rel=\"$index\" value=\"Get info\" />
<div id=\"RIPE_$index\">$info_result[0]</div>
</div>
</td>
</tr>
";
}
$content .=
"
<tr>
<td colspan=\"6\">Vi har totalt ".count($files)." henvendelser.</td>
</tr>
</table>
";
$page->body = $content;
$page->drawPage();
?>
测试内联code
块
答案 0 :(得分:0)
如果超时意味着file_get_contents
超时,我很确定会抛出错误(或者至少返回错误)。据我所知,PHP没有大量的HTTP请求,每次执行都可以满足。
你在这说几件事?你检查过那些项目的价值吗?
您可以尝试使用set_time_limit(0)
,但如果PHP达到最大执行时间,PHP应该抛出错误,因此您可能不需要。
答案 1 :(得分:0)
我认为RIPE有使用限制 - 如果您在一定时间内执行过多查询,可能会被锁定。