Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP脚本即使在退出()后仍继续执行_Php_Performance_Simplexml - Fatal编程技术网

PHP脚本即使在退出()后仍继续执行

PHP脚本即使在退出()后仍继续执行,php,performance,simplexml,Php,Performance,Simplexml,所以我有一个相对简单的PHP脚本 从远程rest服务读取约70个XML文件 使用SimpleXMLElement类(许多新的SimpleXMLElement()调用)解析读取的XML文件 输出到文件json编码的数组,该数组包含关联数组,其中每个数组都有来自这些XML文件的一些感兴趣的属性 脚本的问题是,它完成的时间比将结果输出到文件要晚得多。我在谷歌上搜索了一下,但找不到任何可能导致这样一个问题的东西。下面是描述脚本功能的简化代码 function parseFiles() { $

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

  • 从远程rest服务读取约70个XML文件

  • 使用SimpleXMLElement类(许多新的SimpleXMLElement()调用)解析读取的XML文件

  • 输出到文件json编码的数组,该数组包含关联数组,其中每个数组都有来自这些XML文件的一些感兴趣的属性

脚本的问题是,它完成的时间比将结果输出到文件要晚得多。我在谷歌上搜索了一下,但找不到任何可能导致这样一个问题的东西。下面是描述脚本功能的简化代码

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在centos上运行,问题似乎发生在centos机器上。

问题是由以下原因造成的。不知道发生了什么,但我遇到了有人发现它导致了内存泄漏的地方,所以我重写了代码以解决问题

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