NetworkStream
extends GenericStream
in package
Represents a network socket stream.
Table of Contents
Constants
- CURRENT = SEEK_CUR
- Place the cursor relative to the current position of the cursor.
- END = SEEK_END
- Place the cursor relative to the end of the file.
- READABLE = ['r', 'rb', 'r+', 'r+b', 'w+', 'w+b', 'a+', 'a+b', 'x+', 'x+b', 'c+', 'c+b']
- Readable file modes.
- START = SEEK_SET
- Place the cursor relative to the start of the file.
- WRITEABLE = ['r+', 'r+b', 'w', 'wb', 'w+', 'w+b', 'a', 'ab', 'a+', 'a+b', 'x', 'xb', 'x+', 'x+b', 'c', 'cb', 'c+', 'c+b']
- Writeable file modes.
Methods
- __construct() : mixed
- __destruct() : mixed
- __toString() : string
- canRead() : bool
- Whether this stream is readable.
- canSeek() : bool
- Whether this stream is seekable.
- canWrite() : bool
- Whether this stream is writeable.
- close() : void
- Free, release or reset unmanaged resources.
- copyTo() : void
- Copy the entire contents of this stream to another.
- flush() : void
- Force write of all buffered output to the stream.
- getLength() : int
- Retrieves the current length of the stream.
- getPosition() : int
- Retrieves the current cursor position.
- getResource() : resource
- Returns the underlying resource handle.
- hasTimedOut() : bool
- Whether this stream has timed out.
- isBlocking() : bool
- Whether this stream has blocking operations.
- isEnded() : bool
- Whether the cursor is at the end of the file.
- openAddress() : NetworkStream
- Opens a network socket stream to an endpoint represented by an Index IPAddress instance and port.
- openAddressSSL() : NetworkStream
- Opens an SSL network socket stream to an endpoint represented by an Index IPAddress instance and port.
- openAddressTLS() : NetworkStream
- Opens a TLS network socket stream to an endpoint represented by an Index IPAddress instance and port.
- openEndPoint() : NetworkStream
- Opens a network socket stream to an endpoint represented by an Index EndPoint instance.
- openEndPointSSL() : NetworkStream
- Opens an SSL network socket stream to an endpoint represented by an Index EndPoint instance.
- openEndPointTLS() : NetworkStream
- Opens a TLS network socket stream to an endpoint represented by an Index EndPoint instance.
- openHost() : NetworkStream
- Opens a network socket stream to an endpoint represented by an hostname and port.
- openHostSSL() : NetworkStream
- Opens an SSL network socket stream to an endpoint represented by an hostname and port.
- openHostTLS() : NetworkStream
- Opens a TLS network socket stream to an endpoint represented by an hostname and port.
- openUnix() : NetworkStream
- Opens a network socket stream to an endpoint represented by a UNIX socket path.
- read() : string|null
- Read an amount of data from the stream.
- readByte() : int
- Read a single byte from the stream.
- readChar() : string|null
- Read a single character from the stream.
- readLine() : string|null
- Read a line of text from the stream.
- seek() : bool
- Move the cursor to a different place in the stream.
- setBlocking() : void
- Sets whether the network stream should have blocking reads and writes.
- setLength() : void
- Sets the length of the stream.
- write() : void
- Write an amount of data to the stream.
- writeByte() : void
- Writes a single byte to the stream.
- writeChar() : void
- Writes a single character to the stream.
- writeLine() : void
- Writes a line of text to the stream.
Constants
CURRENT
Place the cursor relative to the current position of the cursor.
public
int
CURRENT
= SEEK_CUR
END
Place the cursor relative to the end of the file.
public
int
END
= SEEK_END
READABLE
Readable file modes.
public
array<string|int, string>
READABLE
= ['r', 'rb', 'r+', 'r+b', 'w+', 'w+b', 'a+', 'a+b', 'x+', 'x+b', 'c+', 'c+b']
START
Place the cursor relative to the start of the file.
public
int
START
= SEEK_SET
WRITEABLE
Writeable file modes.
public
array<string|int, string>
WRITEABLE
= ['r+', 'r+b', 'w', 'wb', 'w+', 'w+b', 'a', 'ab', 'a+', 'a+b', 'x', 'xb', 'x+', 'x+b', 'c', 'cb', 'c+', 'c+b']
Methods
__construct()
public
__construct(string $hostname, int $port, float|null $timeout) : mixed
Parameters
- $hostname : string
-
Hostname to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null
-
Amount of seconds until timeout, null for php.ini default.
Tags
__destruct()
public
__destruct() : mixed
__toString()
public
__toString() : string
Return values
stringcanRead()
Whether this stream is readable.
public
canRead() : bool
Return values
bool —true if the stream is readable.
canSeek()
Whether this stream is seekable.
public
canSeek() : bool
Return values
bool —true if the stream is seekable.
canWrite()
Whether this stream is writeable.
public
canWrite() : bool
Return values
bool —true if the stream is writeable.
close()
Free, release or reset unmanaged resources.
public
close() : void
copyTo()
Copy the entire contents of this stream to another.
public
copyTo(Stream $other) : void
Will seek to the beginning of the stream if the stream is seekable.
Parameters
- $other : Stream
-
Target stream.
Attributes
- #[Override]
flush()
Force write of all buffered output to the stream.
public
flush() : void
getLength()
Retrieves the current length of the stream.
public
getLength() : int
Return values
int —Stream length.
getPosition()
Retrieves the current cursor position.
public
getPosition() : int
Return values
int —Cursor position.
getResource()
Returns the underlying resource handle.
public
getResource() : resource
Return values
resource —Underlying resource handle.
hasTimedOut()
Whether this stream has timed out.
public
hasTimedOut() : bool
Return values
bool —true if the stream has timed out.
isBlocking()
Whether this stream has blocking operations.
public
isBlocking() : bool
Return values
bool —true if the stream has blocking operations.
isEnded()
Whether the cursor is at the end of the file.
public
isEnded() : bool
Return values
bool —true if the cursor is at the end of the file.
openAddress()
Opens a network socket stream to an endpoint represented by an Index IPAddress instance and port.
public
static openAddress(IPAddress $address, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $address : IPAddress
-
Address to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenAddressSSL()
Opens an SSL network socket stream to an endpoint represented by an Index IPAddress instance and port.
public
static openAddressSSL(IPAddress $address, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $address : IPAddress
-
Address to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenAddressTLS()
Opens a TLS network socket stream to an endpoint represented by an Index IPAddress instance and port.
public
static openAddressTLS(IPAddress $address, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $address : IPAddress
-
Address to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenEndPoint()
Opens a network socket stream to an endpoint represented by an Index EndPoint instance.
public
static openEndPoint(EndPoint $endPoint[, float|null $timeout = null ]) : NetworkStream
Parameters
- $endPoint : EndPoint
-
Host to connect to.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenEndPointSSL()
Opens an SSL network socket stream to an endpoint represented by an Index EndPoint instance.
public
static openEndPointSSL(EndPoint $endPoint[, float|null $timeout = null ]) : NetworkStream
Parameters
- $endPoint : EndPoint
-
Host to connect to.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenEndPointTLS()
Opens a TLS network socket stream to an endpoint represented by an Index EndPoint instance.
public
static openEndPointTLS(EndPoint $endPoint[, float|null $timeout = null ]) : NetworkStream
Parameters
- $endPoint : EndPoint
-
Host to connect to.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenHost()
Opens a network socket stream to an endpoint represented by an hostname and port.
public
static openHost(string $hostname, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $hostname : string
-
Hostname to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenHostSSL()
Opens an SSL network socket stream to an endpoint represented by an hostname and port.
public
static openHostSSL(string $hostname, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $hostname : string
-
Hostname to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenHostTLS()
Opens a TLS network socket stream to an endpoint represented by an hostname and port.
public
static openHostTLS(string $hostname, int $port[, float|null $timeout = null ]) : NetworkStream
Parameters
- $hostname : string
-
Hostname to connect to.
- $port : int
-
Port to connect at.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamopenUnix()
Opens a network socket stream to an endpoint represented by a UNIX socket path.
public
static openUnix(string $path[, float|null $timeout = null ]) : NetworkStream
Parameters
- $path : string
-
Path to connect to.
- $timeout : float|null = null
-
Amount of seconds until timeout, null for php.ini default.
Return values
NetworkStreamread()
Read an amount of data from the stream.
public
read(int $length) : string|null
Parameters
- $length : int
-
Maximum amount of data to read.
Return values
string|null —At most a $length sized string or null if we're at the end of the stream.
readByte()
Read a single byte from the stream.
public
readByte() : int
Return values
int —One byte or -1 if we're at the end of the stream.
readChar()
Read a single character from the stream.
public
readChar() : string|null
Return values
string|null —One character or null if we're at the end of the stream.
readLine()
Read a line of text from the stream.
public
readLine() : string|null
Return values
string|null —One line of text or null if we're at the end of the stream.
seek()
Move the cursor to a different place in the stream.
public
seek(int $offset[, int $origin = Stream::START ]) : bool
Parameters
- $offset : int
-
Offset to apply to the cursor position.
- $origin : int = Stream::START
-
Point from which to apply the offset.
Return values
bool —true if the cursor offset was applied successfully.
setBlocking()
Sets whether the network stream should have blocking reads and writes.
public
setBlocking(bool $blocking) : void
Parameters
- $blocking : bool
-
true to block, false to async.
setLength()
Sets the length of the stream.
public
setLength(int $length) : void
Parameters
- $length : int
-
Desired stream length.
write()
Write an amount of data to the stream.
public
write(string $buffer[, int $length = -1 ]) : void
Parameters
- $buffer : string
-
Buffer to write from.
- $length : int = -1
-
Amount of data to write from the buffer, or -1 to write the entire buffer.
writeByte()
Writes a single byte to the stream.
public
writeByte(int $byte) : void
Parameters
- $byte : int
-
Byte to write to the stream.
writeChar()
Writes a single character to the stream.
public
writeChar(string $char) : void
Parameters
- $char : string
-
Character to write to the stream.
writeLine()
Writes a line of text to the stream.
public
writeLine(string $line) : void
Parameters
- $line : string
-
Line of text to write.