AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.
amphp/file
provides non-blocking file system access.
This package can be installed as a Composer dependency.
composer require amphp/file
amphp/file
works out of the box without any PHP extensions.
It uses multiple processes by default, but also comes with a blocking driver that just uses PHP's blocking functions in the current process.
Extensions allow using threading in the background instead of using multiple processes:
Read the specified file's contents:
$contents = Amp\File\read('/path/to/file.txt');
Write the contents string to the specified path:
Amp\File\write('/path/to/file.txt', 'contents');
Open a File
handle for the specified path, e.g. to stream data:
$file = Amp\File\openFile('/path/to/file.txt', 'r');
Amp\ByteStream\pipe($file, getStdout());
Execute a file stat operation.
If the requested path does not exist the function will return null
.
Same as getStatus()
except if the path is a link then the link's data is returned.
If the requested path does not exist the function will return null
.
Checks whether the specified path exists.
Returns the file size in bytes.
Checks whether the given path exists and is a directory.
Checks whether the given path exists and is a regular file.
Checks whether the given path exists and is a symlink.
Returns the file's modification time as Unix timestamp in seconds.
Returns the file's access time as Unix timestamp in seconds.
Returns the file's creation time as Unix timestamp in seconds.
Creates a new hardlink.
Creates a new symlink.
Resolves a symlink to its target path.
Move / rename a file or directory.
Deletes a file.
Creates a directory.
Creates a directory and its parents.
Deletes a directory.
List all files and subdirectories in a directory.
Change the permissions of a file or directory.
Change the ownership of a file or directory.
Update the access and modification time of the specified path.
If the file does not exist it will be created automatically.
Reference to an open file handle.
See also File::isReadable
.
See also File::isWritable
.
See WritableStream::end()
.
Close the file handle.
File::isClosed()
can be used to check if the file handle has already been closed.File::onClose()
can be used ot register a callback that's called on file handle closure.
Set the internal pointer position.
SEEK_SET
: Set position equal to offset bytes.SEEK_CUR
: Set position to current location plus offset.SEEK_END
: Set position to end-of-file plus offset.
Returns the new offset position.
See also File::isSeekable
.
Return the current internal offset position of the file handle.
Test for being at the end of the stream (a.k.a. "end-of-file").
Retrieve the path used when opening the file handle.
Retrieve the mode used when opening the file handle.
Truncates the file to the given length.
If $size
is larger than the current file size, the file is extended with NUL bytes.
amphp/file
follows the semver semantic versioning specification like all other amphp
packages.
If you discover any security related issues, please email [email protected]
instead of using the issue tracker.
The MIT License (MIT). Please see LICENSE
for more information.