Documentation

SocketStream extends Stream
in package

Phrity\Net\SocketStream class.

Table of Contents

Properties

$handler  : mixed
$readable  : mixed
$seekable  : mixed
$stream  : mixed
$writable  : mixed
$readmodes  : mixed
$writemodes  : mixed

Methods

__construct()  : mixed
Create new stream wrapper instance
__toString()  : string
Reads all data from the stream into a string, from the beginning to end.
close()  : void
Closes the stream and any underlying resources.
closeRead()  : void
Closes the stream for further reading.
closeWrite()  : void
Closes the stream for further writing.
detach()  : resource|null
Separates any underlying resources from the stream.
eof()  : bool
Returns true if the stream is at the end of the stream.
getContents()  : string
Returns the remaining contents in a string
getLocalName()  : string|null
Get name of local socket, or null if not connected.
getMetadata()  : array<string|int, mixed>|mixed|null
Get stream metadata as an associative array or retrieve a specific key.
getRemoteName()  : string|null
Get name of remote socket, or null if not connected.
getResource()  : resource|null
Return underlying resource.
getResourceType()  : string
Get type of stream resoucre.
getSize()  : int|null
Get the size of the stream if known.
isBlocking()  : bool|null
If stream is in blocking mode.
isConnected()  : bool
If stream is connected.
isReadable()  : bool
Returns whether or not the stream is readable.
isSeekable()  : bool
Returns whether or not the stream is seekable.
isWritable()  : bool
Returns whether or not the stream is writable.
read()  : string
Read data from the stream.
readLine()  : string|null
Read line from the stream.
rewind()  : void
Seek to the beginning of the stream.
seek()  : void
Seek to a position in the stream.
setBlocking()  : bool
Toggle blocking/non-blocking mode.
setTimeout()  : bool
Set timeout period on a stream.
tell()  : int
Returns the current position of the file read/write pointer
write()  : int
Write data to the stream.
evalStream()  : void
Evaluate stream state.

Properties

$handler

protected mixed $handler

$readable

protected mixed $readable = false

$seekable

protected mixed $seekable = false

$writable

protected mixed $writable = false

$readmodes

private static mixed $readmodes = ['r', 'r+', 'w+', 'a+', 'x+', 'c+']

$writemodes

private static mixed $writemodes = ['r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+']

Methods

__construct()

Create new stream wrapper instance

public __construct(resource $stream) : mixed
Parameters
$stream : resource

A stream resource to wrap

Tags
throws
InvalidArgumentException

If not a valid stream resource

__toString()

Reads all data from the stream into a string, from the beginning to end.

public __toString() : string
Return values
string

close()

Closes the stream and any underlying resources.

public close() : void

closeRead()

Closes the stream for further reading.

public closeRead() : void

closeWrite()

Closes the stream for further writing.

public closeWrite() : void

detach()

Separates any underlying resources from the stream.

public detach() : resource|null

After the stream has been detached, the stream is in an unusable state.

Return values
resource|null

Underlying stream, if any

eof()

Returns true if the stream is at the end of the stream.

public eof() : bool
Return values
bool

getContents()

Returns the remaining contents in a string

public getContents() : string
Tags
throws
StreamException

if unable to read.

throws
StreamException

if error occurs while reading.

Return values
string

getLocalName()

Get name of local socket, or null if not connected.

public getLocalName() : string|null
Return values
string|null

getMetadata()

Get stream metadata as an associative array or retrieve a specific key.

public getMetadata([string $key = null ]) : array<string|int, mixed>|mixed|null
Parameters
$key : string = null

Specific metadata to retrieve.

Return values
array<string|int, mixed>|mixed|null

Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.

getRemoteName()

Get name of remote socket, or null if not connected.

public getRemoteName() : string|null
Return values
string|null

getResource()

Return underlying resource.

public getResource() : resource|null
Return values
resource|null

.

getResourceType()

Get type of stream resoucre.

public getResourceType() : string
Return values
string

getSize()

Get the size of the stream if known.

public getSize() : int|null
Return values
int|null

Returns the size in bytes if known, or null if unknown.

isBlocking()

If stream is in blocking mode.

public isBlocking() : bool|null
Return values
bool|null

isConnected()

If stream is connected.

public isConnected() : bool
Return values
bool

isReadable()

Returns whether or not the stream is readable.

public isReadable() : bool
Return values
bool

isSeekable()

Returns whether or not the stream is seekable.

public isSeekable() : bool
Return values
bool

isWritable()

Returns whether or not the stream is writable.

public isWritable() : bool
Return values
bool

read()

Read data from the stream.

public read(int $length) : string
Parameters
$length : int

Read up to $length bytes from the object and return them.

Tags
throws
StreamException

if an error occurs.

Return values
string

Returns the data read from the stream, or an empty string.

readLine()

Read line from the stream.

public readLine(int $length) : string|null
Parameters
$length : int

Read up to $length bytes from the object and return them.

Tags
throws
StreamException

if an error occurs.

Return values
string|null

Returns the data read from the stream, or null of eof.

rewind()

Seek to the beginning of the stream.

public rewind() : void

If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).

seek()

Seek to a position in the stream.

public seek(int $offset[, int $whence = SEEK_SET ]) : void
Parameters
$offset : int

Stream offset

$whence : int = SEEK_SET

Specifies how the cursor position will be calculated based on the seek offset.

Tags
throws
StreamException

on failure.

setBlocking()

Toggle blocking/non-blocking mode.

public setBlocking(bool $enable) : bool
Parameters
$enable : bool

Blocking mode to set.

Tags
throws
StreamException

if stream is closed.

Return values
bool

If operation was succesful.

setTimeout()

Set timeout period on a stream.

public setTimeout(int $seconds[, int $microseconds = 0 ]) : bool
Parameters
$seconds : int

Seconds to be set.

$microseconds : int = 0

Microseconds to be set.

Tags
throws
StreamException

if stream is closed.

Return values
bool

If operation was succesful.

tell()

Returns the current position of the file read/write pointer

public tell() : int
Tags
throws
StreamException

on error.

Return values
int

Position of the file pointer

write()

Write data to the stream.

public write(string $string) : int
Parameters
$string : string

The string that is to be written.

Tags
throws
StreamException

on failure.

Return values
int

Returns the number of bytes written to the stream.

evalStream()

Evaluate stream state.

protected evalStream() : void

        
On this page

Search results