ILIAS
Release_4_1_x_branch Revision 61804
|
Generalized Socket class. More...
Public Member Functions | |
connect ($addr, $port=0, $persistent=null, $timeout=null, $options=null) | |
Connect to the specified port. | |
disconnect () | |
Disconnects from the peer, closes the socket. | |
isBlocking () | |
Find out if the socket is in blocking mode. | |
setBlocking ($mode) | |
Sets whether the socket connection should be blocking or not. | |
setTimeout ($seconds, $microseconds) | |
Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds. | |
setWriteBuffer ($size) | |
Sets the file buffering size on the stream. | |
getStatus () | |
Returns information about an existing socket resource. | |
gets ($size) | |
Get a specified line of data. | |
read ($size) | |
Read a specified amount of data. | |
write ($data, $blocksize=null) | |
Write a specified amount of data. | |
writeLine ($data) | |
Write a line of data to the socket, followed by a trailing "\r\n". | |
eof () | |
Tests for end-of-file on a socket descriptor. | |
readByte () | |
Reads a byte of data. | |
readWord () | |
Reads a word of data. | |
readInt () | |
Reads an int of data. | |
readString () | |
Reads a zero-terminated string of data. | |
readIPAddress () | |
Reads an IP Address and returns it in a dot formatted string. | |
readLine () | |
Read until either the end of the socket or a newline, whichever comes first. | |
readAll () | |
Read until the socket closes, or until there is no more data in the inner PHP buffer. | |
select ($state, $tv_sec, $tv_usec=0) | |
Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec. | |
enableCrypto ($enabled, $type) | |
Turns encryption on/off on a connected socket. | |
Public Member Functions inherited from PEAR | |
PEAR ($error_class=null) | |
Constructor. | |
_PEAR () | |
Destructor (the emulated type of...). | |
& | getStaticProperty ($class, $var) |
If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. | |
registerShutdownFunc ($func, $args=array()) | |
Use this function to register a shutdown method for static classes. | |
isError ($data, $code=null) | |
Tell whether a value is a PEAR error. | |
setErrorHandling ($mode=null, $options=null) | |
Sets how errors generated by this object should be handled. | |
expectError ($code= '*') | |
This method is used to tell which errors you expect to get. | |
popExpect () | |
This method pops one element off the expected error codes stack. | |
_checkDelExpect ($error_code) | |
This method checks unsets an error code if available. | |
delExpect ($error_code) | |
This method deletes all occurences of the specified element from the expected error codes stack. | |
& | raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false) |
This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. | |
& | throwError ($message=null, $code=null, $userinfo=null) |
Simpler form of raiseError with fewer options. | |
staticPushErrorHandling ($mode, $options=null) | |
staticPopErrorHandling () | |
pushErrorHandling ($mode, $options=null) | |
Push a new error handler on top of the error handler options stack. | |
popErrorHandling () | |
Pop the last error handler used. | |
loadExtension ($ext) | |
OS independant PHP extension load. |
Data Fields | |
$fp = null | |
Socket file pointer. | |
$blocking = true | |
Whether the socket is blocking. | |
$persistent = false | |
Whether the socket is persistent. | |
$addr = '' | |
The IP address to connect to. | |
$port = 0 | |
The port number to connect to. | |
$timeout = false | |
Number of seconds to wait on socket connections before assuming there's no more data. | |
$lineLength = 2048 | |
Number of bytes to read at a time in readLine() and readAll(). | |
Data Fields inherited from PEAR | |
$_debug = false | |
$_default_error_mode = null | |
$_default_error_options = null | |
$_default_error_handler = '' | |
$_error_class = 'PEAR_Error' | |
$_expected_errors = array() |
Net_Socket::connect | ( | $addr, | |
$port = 0 , |
|||
$persistent = null , |
|||
$timeout = null , |
|||
$options = null |
|||
) |
Connect to the specified port.
If called when the socket is already connected, it disconnects and connects again.
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. |
public
Definition at line 97 of file Socket.php.
References $addr, $fp, $persistent, $port, $timeout, PEAR\raiseError(), and setBlocking().
Net_Socket::disconnect | ( | ) |
Disconnects from the peer, closes the socket.
public
Definition at line 171 of file Socket.php.
References PEAR\raiseError().
Net_Socket::enableCrypto | ( | $enabled, | |
$type | |||
) |
Turns encryption on/off on a connected socket.
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. |
public
Definition at line 580 of file Socket.php.
References PEAR\raiseError().
Net_Socket::eof | ( | ) |
Tests for end-of-file on a socket descriptor.
Also returns true if the socket is disconnected.
public
Definition at line 374 of file Socket.php.
Net_Socket::gets | ( | $size | ) |
Get a specified line of data.
public
Definition at line 283 of file Socket.php.
References $size, and PEAR\raiseError().
Net_Socket::getStatus | ( | ) |
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
public
Definition at line 267 of file Socket.php.
References PEAR\raiseError().
Net_Socket::isBlocking | ( | ) |
Find out if the socket is in blocking mode.
public
Definition at line 188 of file Socket.php.
References $blocking.
Net_Socket::read | ( | $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.
integer | $size | The number of bytes to read from the socket. public |
Definition at line 303 of file Socket.php.
References $size, and PEAR\raiseError().
Net_Socket::readAll | ( | ) |
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).
public
Definition at line 507 of file Socket.php.
References $data, and PEAR\raiseError().
Net_Socket::readByte | ( | ) |
Reads a byte of data.
public
Definition at line 386 of file Socket.php.
References PEAR\raiseError().
Net_Socket::readInt | ( | ) |
Reads an int of data.
public
Definition at line 419 of file Socket.php.
References PEAR\raiseError().
Net_Socket::readIPAddress | ( | ) |
Reads an IP Address and returns it in a dot formatted string.
public
Definition at line 457 of file Socket.php.
References PEAR\raiseError().
Net_Socket::readLine | ( | ) |
Read until either the end of the socket or a newline, whichever comes first.
Strips the trailing newline from the returned data.
public
Definition at line 477 of file Socket.php.
References $timeout, and PEAR\raiseError().
Net_Socket::readString | ( | ) |
Reads a zero-terminated string of data.
public
Definition at line 437 of file Socket.php.
References PEAR\raiseError().
Net_Socket::readWord | ( | ) |
Reads a word of data.
public
Definition at line 402 of file Socket.php.
References PEAR\raiseError().
Net_Socket::select | ( | $state, | |
$tv_sec, | |||
$tv_usec = 0 |
|||
) |
Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec.
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. |
public
Definition at line 532 of file Socket.php.
References $fp, $result, NET_SOCKET_ERROR, NET_SOCKET_READ, NET_SOCKET_WRITE, and PEAR\raiseError().
Net_Socket::setBlocking | ( | $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.
boolean | $mode | True for blocking sockets, false for nonblocking. public |
Definition at line 203 of file Socket.php.
References PEAR\raiseError().
Referenced by connect().
Net_Socket::setTimeout | ( | $seconds, | |
$microseconds | |||
) |
Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds.
integer | $seconds | Seconds. |
integer | $microseconds | Microseconds. public |
Definition at line 223 of file Socket.php.
References PEAR\raiseError().
Net_Socket::setWriteBuffer | ( | $size | ) |
Sets the file buffering size on the stream.
See php's stream_set_write_buffer for more information.
integer | $size | Write buffer size. public |
Definition at line 240 of file Socket.php.
References $size, and PEAR\raiseError().
Net_Socket::write | ( | $data, | |
$blocksize = null |
|||
) |
Write a specified amount of data.
string | $data | Data to write. |
integer | $blocksize | Amount of data to write at once. NULL means all at once. |
public
Definition at line 324 of file Socket.php.
References $data, $size, and PEAR\raiseError().
Net_Socket::writeLine | ( | $data | ) |
Write a line of data to the socket, followed by a trailing "\r\n".
public
Definition at line 357 of file Socket.php.
References $data, and PEAR\raiseError().
string Net_Socket::$addr = '' |
boolean Net_Socket::$blocking = true |
Whether the socket is blocking.
Defaults to true.
Definition at line 47 of file Socket.php.
Referenced by isBlocking().
resource Net_Socket::$fp = null |
Socket file pointer.
Definition at line 41 of file Socket.php.
integer Net_Socket::$lineLength = 2048 |
Number of bytes to read at a time in readLine() and readAll().
Defaults to 2048.
Definition at line 79 of file Socket.php.
boolean Net_Socket::$persistent = false |
Whether the socket is persistent.
Defaults to false.
Definition at line 53 of file Socket.php.
Referenced by connect().
integer Net_Socket::$port = 0 |
integer Net_Socket::$timeout = false |
Number of seconds to wait on socket connections before assuming there's no more data.
Defaults to no timeout.
Definition at line 72 of file Socket.php.
Referenced by connect(), and readLine().