0

我有一个充满 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

4

2 回答 2

0

如果超时是指file_get_contents超时,我很确定这会引发错误(或至少返回错误)。据我所知,PHP 每次执行都没有大量的 HTTP 请求。

你在这里说多少项目?你检查过这些项目的值吗?

您可以尝试使用set_time_limit(0),但如果 PHP 达到最大执行时间,PHP 应该会抛出错误,因此您可能不需要它。

于 2010-09-14T15:30:20.747 回答
0

我认为 RIPE 有使用限制 - 如果您在一定时间内执行太多查询,您可能会被锁定。

于 2010-09-14T15:54:43.447 回答