Jump to content

Completion Of File Write


ameliabob

Recommended Posts

I am having a timitng problem when trying to write an XML file with the statement

		file_put_contents( $userProfileFileName, $XMLprofile->asXML());

It does not seem to be completed before the program goes on. I am trying to read it later but it has not been updated.My thoughts are a buffer that is not getting flushed on the write or a buffer that is being held in the serverAny help would be appreciated.

Link to comment
Share on other sites

I'd suggest you put in a log of some sort to track if and when the writing is successful. If this code is still experimental, normal echoes will also do:

echo 'Writing to file at ', microtime(true) ,'...';file_put_contents( $userProfileFileName, $XMLprofile->asXML());echo 'File writing completed at ', microtime(true);

And log file access in a similar fashion.Either way, the microtime is there to ensure that each output will be unique. If there's some sort of server caching (which is what I'd suggest is the case), this should eliminate it or at least make it visible as such - if the start of the reading time is a smaller number than the start of the writing time, or the times don't change, it's a race condition or a caching issue respectively.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...