Are rename() and unlink() asynchronous functions?

后端 未结 4 693
萌比男神i
萌比男神i 2021-01-22 09:37

I have strong reason to believe that both functions rename() and unlink() are asynchronous, which, from my understanding, means that when the functions are called, the code belo

相关标签:
4条回答
  • 2021-01-22 10:02

    Mind that file-systems often use caches to reduce the load. Normally you won't notice, but sometimes you need to clear the cache if you need to have the real information. Check the configuration of your file-system if your issue is file-system related.

    PHP itself uses a cache as well for some file-operations, so clear that, too.

    See clearstatcache to clear the PHP stat cache.

    Take note that this is a "view" issue, the file is actually deleted on disk, but PHP might still return it's there (until you clear the cache).

    0 讨论(0)
  • 2021-01-22 10:07

    I suppose they are not asynchronous, because they return a result telling if the operation was successful or not.

    I believe the problem happens because when you run scandir after making the modifications, it may be using "cached" data, from memory, instead of re-scanning the file system.

    0 讨论(0)
  • To use any file operation you are required to use the $_SERVER["DOCUMENT_ROOT"] to make that work. In case you wont do it.. the real operation wont work properly. Also in case you are using the Linux Server then you will be required to set the permissions for the folders in which you want to perform the file operation.

    And mind it both the operations are synchronous they are not asynchronous. It also depends on the type of the server or the OS that you are using.

    0 讨论(0)
  • 2021-01-22 10:25

    rename() is not, but unlink() is asynchronous on Windows.

    Because there seems to be no way of waiting for a pending delete to finish, this answer suggests to rename a file before deleting it. PHP does not seem to do that, so you can assume it's asynchronous.

    0 讨论(0)
提交回复
热议问题