Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
Client Class Reference

Public Member Functions

 __construct ( $host, $port=null, $timeout=30, $secure=false, $context=array(), array $params=array())
 Constructor.
 
 __clone ()
 This object can not be cloned.
 
 __get ($name)
 
 __sleep ()
 This object can not be serialized.
 
 close ()
 Close the connection.
 
 gets ($size)
 Returns a line of data.
 
 getStatus ()
 Returns information about the connection.
 
 read ($size)
 Returns a specified amount of data.
 
 startTls ()
 Start a TLS connection.
 
 write ($data)
 Writes data to the stream.
 

Protected Member Functions

 _checkStream ()
 Throws an exception is the stream is not a resource.
 
 _connect ( $host, $port, $timeout, $secure, $context, $retries=0)
 Connect to the remote server.
 

Protected Attributes

boolean $_connected = false
 Is there an active connection?
 
array $_params
 Configuration parameters.
 
boolean $_secure = false
 Is the connection secure?
 
resource $_stream
 The actual socket.
 

Constructor & Destructor Documentation

◆ __construct()

Client::__construct ( $host,
$port = null,
$timeout = 30,
$secure = false,
$context = array(),
array $params = array() )

Constructor.

Parameters
string$hostHostname of remote server (can contain protocol prefx).
integer$portPort number of remote server.
integer$timeoutConnection timeout (in seconds).
mixed$secureSecurity layer requested. One of:
  • false: (No encryption) [DEFAULT]
  • 'ssl': (Auto-detect SSL version)
  • 'sslv2': (Force SSL version 3)
  • 'sslv3': (Force SSL version 2)
  • 'tls': (TLS; started via protocol-level negotation over unencrypted channel)
  • 'tlsv1': (TLS version 1.x connection)
  • true: (TLS if available/necessary)
array$contextAny context parameters passed to stream_create_context().
array$paramsAdditional options.
Exceptions
Horde\Socket\Client\Exception

Member Function Documentation

◆ _checkStream()

Client::_checkStream ( )
protected

Throws an exception is the stream is not a resource.

Exceptions
Horde\Socket\Client\Exception

◆ _connect()

Client::_connect ( $host,
$port,
$timeout,
$secure,
$context,
$retries = 0 )
protected

Connect to the remote server.

See also
__construct()
Exceptions
Horde\Socket\Client\Exception

◆ gets()

Client::gets ( $size)

Returns a line of data.

Parameters
int$sizeReading ends when $size - 1 bytes have been read, or a newline or an EOF (whichever comes first).
Exceptions
Horde\Socket\Client\Exception
Return values
string\$sizebytes of data from the socket

◆ getStatus()

Client::getStatus ( )

Returns information about the connection.

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
Exceptions
Horde\Socket\Client\Exception
Return values
arrayInformation about existing socket resource.

◆ read()

Client::read ( $size)

Returns a specified amount of data.

Parameters
integer$sizeThe number of bytes to read from the socket.
Exceptions
Horde\Socket\Client\Exception
Return values
string\$sizebytes of data from the socket.

◆ startTls()

Client::startTls ( )

Start a TLS connection.

Return values
booleanWhether TLS was successfully started.

◆ write()

Client::write ( $data)

Writes data to the stream.

Parameters
string$dataData to write.
Exceptions
Horde\Socket\Client\Exception

The documentation for this class was generated from the following file: