PHP 脚本即使在 exit() 之后继续执行

PHP script continues execution even after exit()

所以我有一个相对简单的 PHP 脚本

脚本的问题在于它完成的时间比将结果输出到文件的时间晚得多。我用谷歌搜索但找不到任何可能导致此类问题的东西。下面是描述我的脚本做什么的简化代码。

function parseFiles()
{
    $fileData = array();
    $parsedData = array();

    // read files using curl, output is an array of SimpleXMLElements
    readXMLFiles($fileData);

    // for each XML object create an assoc array which contains attributes
    // of interest, add it to $parsedData
    parseData($fileData, $parsedData);

    file_put_contents("test.txt", json_encode($parsedData));

    /*
    This is where the problem occures, the scipt outputs result to the file
    MUCH faster than it ends execution for example file is created with data
    in ~ 15 seconds but the script ends in 60 seconds 
    (so the exit() command took 45 seconds????)
    */
    exit();
}

这会不会是在到达 exit() 时由某种垃圾收集引起的?那些 XML 对象相对较大...我还尝试 运行 wamp 堆栈上的脚本和 PHP,apache 运行ning 在 centos 上,问题似乎在centos机器上发生。

问题是由解决问题的 SimpleXML class. No idea what was happening, but I came across issue where someone found that it was causing memory leaks, so I rewrote my code to work with DOMDocument class 引起的。

之前脚本会挂起约 2 分钟,重写后它会在 13 秒内完成 ;)