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