Class NSafeStream
Thread safe / atomic file manipulation. Stream safe://
file_put_contents('safe://myfile.txt', $content);
$content = file_get_contents('safe://myfile.txt');
unlink('safe://myfile.txt');
Methods summary
public static
boolean
|
#
register( )
Registers protocol 'safe://'.
Registers protocol 'safe://'.
Returns
boolean
|
public
boolean
|
#
stream_open( string $path, string $mode, integer $options, string & $opened_path )
Opens file.
Parameters
- $path
string file name with stream protocol
- $mode
string mode - see fopen()
- $options
integer STREAM_USE_PATH, STREAM_REPORT_ERRORS
- $opened_path
string full path
Returns
boolean TRUE on success or FALSE on failure
|
public
|
|
public
string
|
#
stream_read( integer $length )
Reads up to length bytes from the file.
Reads up to length bytes from the file.
Parameters
Returns
string
|
public
integer
|
#
stream_write( string $data )
Writes the string to the file.
Writes the string to the file.
Parameters
- $data
string data to write
Returns
integer number of bytes that were successfully stored
|
public
integer
|
#
stream_tell( )
Returns the position of the file.
Returns the position of the file.
Returns
integer
|
public
boolean
|
#
stream_eof( )
Returns TRUE if the file pointer is at end-of-file.
Returns TRUE if the file pointer is at end-of-file.
Returns
boolean
|
public
integer
|
#
stream_seek( integer $offset, integer $whence )
Sets the file position indicator for the file.
Sets the file position indicator for the file.
Parameters
- $offset
integer position
- $whence
integer see fseek()
Returns
integer Return TRUE on success
|
public
array
|
#
stream_stat( )
Gets information about a file referenced by $this->handle.
Gets information about a file referenced by $this->handle.
Returns
array
|
public
array
|
#
url_stat( string $path, integer $flags )
Gets information about a file referenced by filename.
Gets information about a file referenced by filename.
Parameters
- $path
string file name
- $flags
integer STREAM_URL_STAT_LINK, STREAM_URL_STAT_QUIET
Returns
array
|
public
boolean
|
#
unlink( string $path )
Deletes a file. On Windows unlink is not allowed till file is opened
Deletes a file. On Windows unlink is not allowed till file is opened
Parameters
- $path
string file name with stream protocol
Returns
boolean TRUE on success or FALSE on failure
|
Constants summary
string
|
PROTOCOL
|
'safe' |
#
Name of stream protocol - safe://
Name of stream protocol - safe://
|