PEAR Handbuch | ||
---|---|---|
Zurück | Nach vorne |
Socket enables comfortable handling Socket connections.
Beispiel 1. Using Socket
|
Connect to the specified port. If called when the socket is already connected, it disconnects and connects again.
Parameter
$addr - IP address or host name
$port - TCP port number
$persistent - whether the connection is persistent (kept open between requests by the web server). Default is false, no persistent connection
$timeout - how long to wait for data
Returns
mixed - true on success or a PEAR_Error
Disconnects from the peer, closes the socket.
Returns
mixed - true on success or a PEAR_Error otherwise
Find out if the socket is in blocking mode.
Returns
boolean - the current blocking 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.
Warnung |
If you use readAll() on a connection in blocking mode, the function will be not terminated until the socket connection will be closed. |
Parameter
$mode - true for blocking sockets, false for nonblocking
Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds
Parameter
$seconds - seconds part
$microseconds - microseconds part
Returns
mixed - true on success or a PEAR_Error on failure
Returns information about an existing socket resource. Currently returns four entries in the result array:
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
Returns
mixed - result array on success or a PEAR_Error on failure
Returns a string containing data from the socket connection
Parameter
$size - max number of chars to recieve
Returns
mixed - the data as string or a PEAR_Error on failure
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.
Parameter
$size - max number of bytes to read from the socket
Returns
mixed - the data as string or a PEAR_Error if not connected
Write data to a socket connection
Parameter
$data - the data to write
Returns
mixed - PEAR_Error, if not connected or the message of the write function
Write a line of data to a socket connection, followed by a trailing "\r\n".
Parameter
$data - the data to write
Returns
mixed - fputs result, or an PEAR_Error
fire true if the connection is closed or input stream finished
Returns
boolean - true, if no connection exists anymore
Read a byte from the socket stream
Returns
mixed - data from the socket, or a PEAR_Error if not connected.
Reads a word from the socket stream Word means a binary word, not a word in a language
Returns
mixed - data from the socket, or a PEAR_Error if not connected.
Reads a integer number from the socket stream. The length of a integer is 4 bytes
Returns
mixed - data from the socket, or a PEAR_Error if not connected.
Reads a IP from the socket stream The function expect a integer which will converted to a IP address. This function only works with IPv4 addresses.
Returns
mixed - data from the socket, or a PEAR_Error if not connected.
Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.
Returns
mixed - All available data up to a newline, without that newline, or until the end of the socket as string. else a PEAR_Error when not connected.
Read until the socket closes. THIS FUNCTION WILL NOT EXIT if the socket is in blocking mode until the socket closes.
Returns
mixed - All data until the socket closes as string, or PEAR_Error if not connected.
Zurück | Zum Anfang | Nach vorne |
Networking functions | Nach oben | PEAR System |