开发者

Waiting for xml file writing to finish in PHP

My PHP knowledge is limited and I'm having a problem with a script I am running.

I am amalgamating quite a few xml feeds and writing the output to my own server in a custom xml file.

I am using XMLWriter to do this, but the problem I 开发者_StackOverflow中文版am having is knowing when the file has successful finished being written to?

I am loading the external feeds via SimpleXMLElement, and in total the script takes around 10 seconds to run, but when I do a print_r($xmlWriter) at the end of the script it is empty, so too is the xml file Im trying to write.

The xml file is successfully written, but in the content of php im not sure when and would like only to proceed to some other code once this is successful.

Any help appreciated

Thanks


You could check if $xmlWriter is empty, as you say this is the problem, and loop until it is not empty, but at the same time you can tell PHP to wait a while to save performance:

//while the XML hasn't finished being written yet
while ($xmlWriter == "") {
  // sleep for 10 seconds
  sleep(10);
}

You could even keep a count of how long it waits for and give up after a while and handle the failure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜