Search code examples
phpoverwritephp-ziparchive

php - What will happen if I overwrite the file itself when it is executing (using ZipArchive)


So as described in question itself, I want to replace the file from which a zip archive is opened and then which is overwriting files with new version.

If still my question is not clear then the thing I want to do is I want to get a zip file from a server and then unzip using CLASS "ZipArchive" and then over write everyfile which is in Zip to destination location, the problem will be the php file by which this thing is happening will gonna be overwritten.

So will the php generate the error or the process will go whatever we want?


Solution

  • On Linux files are not usually locked (see https://unix.stackexchange.com/questions/147392/what-is-advisory-locking-on-files-that-unix-systems-typically-employs) so you can do whatever you want with that file. PHP works with that file in memory so you can overwrite it during it's execution.

    But if you will run the script multiple times while the first one is in progress it might load incomplete version and then it will throw some error so it might be wise to make sure that won't happen (using locks) or try to do some more atomic approach.

    Windows locks files so I assume you won't be able to extract files the same way there.