boolean connect(
string
$addr, [integer
$port = 0], [boolean
$persistent = null], [integer
$timeout = null], [array
$options = null]
)
|
|
Connect to the specified port. If called when the socket is already connected, it disconnects and connects again.
Parameters:
|
string |
$addr: |
IP address or host name. |
|
integer |
$port: |
TCP port number. |
|
boolean |
$persistent: |
(optional) Whether the connection is persistent (kept open between requests by the web server). |
|
integer |
$timeout: |
(optional) How long to wait for data. |
|
array |
$options: |
See options for stream_context_create. |
API Tags:
| Return: | | PEAR_Error True on success or a PEAR_Error on failure. |
| Access: | public |
Disconnects from the peer, closes the socket.
API Tags:
| Return: | true on success or an error object otherwise |
| Access: | public |
false enableCrypto(
bool
$enabled, integer
$type
)
|
|
Turns encryption on/off on a connected socket.
Parameters:
|
bool |
$enabled: |
Set this parameter to true to enable encryption and false to disable encryption. |
|
integer |
$type: |
Type of encryption. See http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values. |
API Tags:
| Return: | on error, true on success and 0 if there isn't enough data and the user should try again (non-blocking sockets only). A PEAR_Error object is returned if the socket is not connected |
| Access: | public |
Tests for end-of-file on a socket descriptor.
Also returns true if the socket is disconnected.
API Tags:
Get a specified line of data
Parameters:
API Tags:
| Return: | bytes of data from the socket, or a PEAR_Error if not connected. |
| Access: | public |
Returns information about an existing socket resource.
Currently returns four entries in the result array:
<p>
timed_out (bool) - The socket timed out waiting for data
blocked (bool) - The socket was blocked
eof (bool) - Indicates EOF event
unread_bytes (int) - Number of bytes left in the socket buffer
</p>
API Tags:
| Return: | Array containing information about existing socket resource or an error object otherwise |
| Access: | public |
Find out if the socket is in blocking mode.
API Tags:
| Return: | The current blocking mode. |
| Access: | public |
$size read(
integer
$size
)
|
|
Read a specified amount of data. This is guaranteed to return, and has the added benefit of getting everything in one fread() chunk; if you know the size of the data you're getting beforehand, this is definitely the way to go.
Parameters:
|
integer |
$size: |
The number of bytes to read from the socket. |
API Tags:
| Return: | bytes of data from the socket, or a PEAR_Error if not connected. |
| Access: | public |
Read until the socket closes, or until there is no more data in
the inner PHP buffer. If the inner buffer is empty, in blocking mode we wait for at least 1 byte of data. Therefore, in blocking mode, if there is no data at all to be read, this function will never exit (unless the socket is closed on the remote end).
API Tags:
| Return: | All data until the socket closes, or a PEAR_Error if not connected. |
| Access: | public |
Reads a byte of data
API Tags:
| Return: | byte of data from the socket, or a PEAR_Error if not connected. |
| Access: | public |
Reads an int of data
API Tags:
| Return: | 1 int of data from the socket, or a PEAR_Error if not connected. |
| Access: | public |
Reads an IP Address and returns it in a dot formated string
API Tags:
| Return: | formated string, or a PEAR_Error if not connected. |
| Access: | public |
Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.
API Tags:
| Return: | available data up to a newline, without that newline, or until the end of the socket, or a PEAR_Error if not connected. |
| Access: | public |
Reads a zero-terminated string of data
API Tags:
| Return: | or a PEAR_Error if not connected. |
| Access: | public |
Reads a word of data
API Tags:
| Return: | word of data from the socket, or a PEAR_Error if not connected. |
| Access: | public |
False select(
integer
$state, integer
$tv_sec, [integer
$tv_usec = 0]
)
|
|
Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec.
Parameters:
|
integer |
$state: |
Which of read/write/error to check for. |
|
integer |
$tv_sec: |
Number of seconds for timeout. |
|
integer |
$tv_usec: |
Number of microseconds for timeout. |
API Tags:
| Return: | if select fails, integer describing which of read/write/error are ready, or PEAR_Error if not connected. |
| Access: | public |
mixed setBlocking(
boolean
$mode
)
|
|
Sets whether the socket connection should be blocking or not. A read call to a non-blocking socket will return immediately if there is no data available, whereas it will block until there is data for blocking sockets.
Parameters:
|
boolean |
$mode: |
True for blocking sockets, false for nonblocking. |
API Tags:
| Return: | true on success or an error object otherwise |
| Access: | public |
mixed setTimeout(
integer
$seconds, integer
$microseconds
)
|
|
Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds
Parameters:
|
integer |
$seconds: |
Seconds. |
|
integer |
$microseconds: |
Microseconds. |
API Tags:
| Return: | true on success or an error object otherwise |
| Access: | public |
mixed setWriteBuffer(
integer
$size
)
|
|
Sets the file buffering size on the stream.
See php's stream_set_write_buffer for more information.
Parameters:
|
integer |
$size: |
Write buffer size. |
API Tags:
| Return: | on success or an PEAR_Error object otherwise |
| Access: | public |
mixed write(
string
$data, [integer
$blocksize = null]
)
|
|
Write a specified amount of data.
Parameters:
|
string |
$data: |
Data to write. |
|
integer |
$blocksize: |
Amount of data to write at once. NULL means all at once. |
API Tags:
| Return: | true on success or an error object otherwise |
| Access: | public |
Write a line of data to the socket, followed by a trailing "\r\n".
Parameters:
API Tags:
| Return: | fputs result, or an error |
| Access: | public |