I think that quite often in the corporate admin panel, or simply the administrative part of any site, there is a need to process a large number of files and show the status of the operation to the user.
It can be batch processing of filled images, product backup documents, fill a large database dump and so on. When writing my file manager (wait for the explosion of popularity in 2010;)) I wrote a simple library for organizing file operations, showing the status of the operation to the user.
The idea behind it is very simple:
Any operation on files can be divided into several components:
- getting the list of files that are needed for work, and organizing the correct “opening” of directories - without recursion (why, I will explain later)
- direct file processing:
- start file processing (for example, opening a file handle)
- cycle ( until the file is processed ) {
- repeating piece ...
- }
- end of file processing (for example, closing a file handle)
If this is a file copy operation, or a dump, then all stages will be present. For simpler operations, such as deleting files, there may be no loop, no final stage.
What is it all for? Why so hard?
Now that we have understood what parts the operation on files can consist of, let's get down to the most important thing: what does it give in the appendix to our task (to show the status of a complex and lengthy operation on files)?
')
This gives the following:
- Saving the whole tree of files waiting for processing (remember, I was talking about non-recursive directory tree disclosing algorithms?)
- Theoretical ability to save the state of the operation in any place (that is, immediately after the start, or somewhere in the middle of the cycle)
- As a consequence of the previous two, the ability to plan to interrupt the operation at regular intervals to show the status of the operation to the user, and again start from the last memorized place
- (Not implemented) Ability to control operation errors directly during its execution, without losing state and complete completion of work
What will change for the user?
Before:
loading ...
(after half an hour) 504 gateway timeout
After:
starting convert ...
...
(status update every 5 seconds) loading (123 of 3000 files converted) ...
...
operation complete
Where is the library itself?
The very text of the library (150 lines with comments) and a simple example of use are here:
forum.dklab.ru/viewtopic.php?p=146572#146572Use in my file manager:
demo.dolphin-php.org (login login, password password, version - full) (copy, delete, CHMOD files, ...)
A more detailed description in the .doc format [English]:
m.forum.dklab.ru/files/multipart.rar