简体   繁体   中英

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM