Wrapper
class Wrapper
| internal |
Provides isolation for thread safe file manipulation using stream nette.safe://
file_put_contents('nette.safe://myfile.txt', $content);
$content = file_get_contents('nette.safe://myfile.txt');
unlink('nette.safe://myfile.txt'); Constants
| Protocol |
Name of stream protocol - nette.safe:// |
| PROTOCOL |
|
Properties
| ?resource | $context |
Methods
Registers protocol 'nette.safe://'.
Opens the file and acquires the appropriate lock (LOCK_SH for reading, LOCK_EX for writing).
Releases the lock and closes the file. Truncates back to $startPos if a write error occurred.
No description
Writes data to the file. Sets the write-error flag if fewer bytes than expected were written.
Truncates a file to a given length.
Returns the position of the file.
Returns true if the file pointer is at end-of-file.
Sets the file position indicator for the file.
Gets information about a file referenced by $this->handle.
Returns file information for the given path. Not thread-safe.
Deletes a file. On Windows, fails if the file is currently open.
Required since PHP 7.4 when the wrapper is used for includes; always returns false.
Details
at line 47
static bool
register()
Registers protocol 'nette.safe://'.
at line 62
bool
stream_open(string $path, string $mode, int $options)
Opens the file and acquires the appropriate lock (LOCK_SH for reading, LOCK_EX for writing).
Converts 'w' mode to 'c' to avoid truncation before the lock is held, then truncates manually. For reads, retries up to 100 times if the file is empty (another thread may be writing).
at line 100
void
stream_close()
Releases the lock and closes the file. Truncates back to $startPos if a write error occurred.
at line 112
string|false
stream_read(int $length)
No description
at line 121
int|false
stream_write(string $data)
Writes data to the file. Sets the write-error flag if fewer bytes than expected were written.
at line 138
bool
stream_truncate(int $size)
Truncates a file to a given length.
at line 147
int
stream_tell()
Returns the position of the file.
at line 156
bool
stream_eof()
Returns true if the file pointer is at end-of-file.
at line 165
bool
stream_seek(int $offset, int $whence = SEEK_SET)
Sets the file position indicator for the file.
at line 175
array|false
stream_stat()
Gets information about a file referenced by $this->handle.
at line 185
array|false
url_stat(string $path, int $flags)
Returns file information for the given path. Not thread-safe.
at line 196
bool
unlink(string $path)
Deletes a file. On Windows, fails if the file is currently open.
at line 206
bool
stream_set_option(int $option, int $arg1, int $arg2)
Required since PHP 7.4 when the wrapper is used for includes; always returns false.