简体   繁体   English

php-如果我在执行文件时覆盖文件本身(使用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. 因此,正如问题本身所描述的那样,我要替换从中打开zip存档的文件,然后用新版本覆盖文件。

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. 如果仍然不清楚我的问题,那么我想做的是从服务器获取一个zip文件,然后使用CLASS“ ZipArchive”解压缩,然后将Zip中的每个文件覆盖到目标位置,问题将是发生这种情况的php文件将被覆盖。

So will the php generate the error or the process will go whatever we want? 那么,php会生成错误,还是过程将随我们所愿?

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. 在Linux上,文件通常不会被锁定(请参阅https://unix.stackexchange.com/questions/147392/what-is-advisory-locking-on-files-that-unix-systems-typically-employs ),因此您可以执行任何操作您想要该文件。 PHP works with that file in memory so you can overwrite it during it's execution. PHP在内存中使用该文件,因此您可以在执行过程中将其覆盖。

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. Windows会锁定文件,因此我假设您将无法以相同的方式提取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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