[英]PHP script continues execution even after exit()
所以我有一個相對簡單的PHP腳本
從遠程休息服務讀取〜70個XML文件;
使用SimpleXMLElement類解析讀取的XML文件(許多新的SimpleXMLElement()調用);
輸出到文件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機器上。
該問題是由SimpleXML類引起的。 不知道發生了什么,但是我遇到了一個問題 ,有人發現這導致了內存泄漏,因此我重寫了代碼以與DOMDocument類一起使用來解決問題。
在腳本掛起〜2分鍾之前,重寫之后在13秒內完成;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.