I am writing a SQL query results to a file and once I am done writing it to a file I need to output the file to user for download. My Question is how do i know when the file is completely written as different SQL query takes different amount of time. Is there anyway I can know that a file is completely written using PHP ?
Share
Your question lacks a lot of details, so I don’t think a definitive answer can be given.
If the file system you are using allows you to open a file with exclusive write access, then the query script can open the file in that way, and then on the other script you simply try to open the file with write access repeatedly until the call succeeds, at which point you know the other process closed it.
Assuming the above is not possible, another option is to implement some mechanism by which the query script can signal to the other script that the writing is complete. For example, you could write some sort of marker as the last line of the file, something that is guaranteed to never appear as part of the output of the SQL query.
I hope this helps. If it doesn’t, you may want to add more details to your question so that the problem can be understood better.