-
Notifications
You must be signed in to change notification settings - Fork 15
File
When you pass a file resource handle a PHP+QB function, QB will try to access the contents of the file using the operation system's memory-mapped file mechanism. Functionally, this is equivalent to loading the contents first with [file_get_contents|http://php.net/manual/pl/function.file-get-contents.php], then passing the string to the PHP+QB function. The use of memory-mapped file can be much more efficient, however. The operation system will only page in the data when it's accessed. Contents not visited by the running code will not be loaded. Multiple processes accessing the same file will also share the physical memory.
For a parameter that is passed by reference, the file must have been opened in read-write mode ("w+") for the mapping operation to succeed. A file opened in write-only mode ("w") cannot be memory-mapped as there is no such thing as write-only memory.
Resizing an array backed by a writable file will cause the file itself to expand. QB will increase the file size in 1024-byte increment. When the function returns, QB will then slim the file to match the array's actual size.
If your code modify a parameter that isn't passed by reference, QB will not map the file into memory as it'll lead to a memory protection fault.
If QB is unable to map a file for one or another, it will allocate a block of memory and load in it contents. Then on return, QB will write the in-memory contents to the file if the parameter was passed by reference.
The configuration directive qb.allow_memory_map controls whether the use of memory-mapped files is allowed.