Documentation

Client
in package

Utility interface for establishing a stream socket client.

Tags
author

Michael Slusarz slusarz@horde.org

author

Jan Schneider jan@horde.org

category

Horde

copyright

2013-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Table of Contents

$connected  : bool
$secure  : bool
$_connected  : bool
Is there an active connection?
$_params  : array<string|int, mixed>
Configuration parameters.
$_secure  : bool
Is the connection secure?
$_stream  : resource
The actual socket.
__clone()  : mixed
This object can not be cloned.
__construct()  : mixed
Constructor.
__get()  : mixed
__sleep()  : mixed
This object can not be serialized.
close()  : mixed
Close the connection.
gets()  : string
Returns a line of data.
getStatus()  : array<string|int, mixed>
Returns information about the connection.
read()  : string
Returns a specified amount of data.
startTls()  : bool
Start a TLS connection.
write()  : mixed
Writes data to the stream.
_checkStream()  : mixed
Throws an exception is the stream is not a resource.
_connect()  : mixed
Connect to the remote server.

Properties

$connected read-only

public bool $connected

Is there an active connection?

$secure read-only

public bool $secure

Is the active connection secure?

$_connected

Is there an active connection?

protected bool $_connected = false

$_params

Configuration parameters.

protected array<string|int, mixed> $_params

$_secure

Is the connection secure?

protected bool $_secure = false

$_stream

The actual socket.

protected resource $_stream

Methods

__clone()

This object can not be cloned.

public __clone() : mixed
Return values
mixed

__construct()

Constructor.

public __construct(string $host[, int $port = null ][, int $timeout = 30 ][, mixed $secure = false ][, array<string|int, mixed> $context = array() ][, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$host : string

Hostname of remote server (can contain protocol prefx).

$port : int = null

Port number of remote server.

$timeout : int = 30

Connection timeout (in seconds).

$secure : mixed = false

Security 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)
$context : array<string|int, mixed> = array()

Any context parameters passed to stream_create_context().

$params : array<string|int, mixed> = array()

Additional options.

Tags
throws
Exception
Return values
mixed

__get()

public __get(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

__sleep()

This object can not be serialized.

public __sleep() : mixed
Return values
mixed

close()

Close the connection.

public close() : mixed
Return values
mixed

gets()

Returns a line of data.

public gets(int $size) : string
Parameters
$size : int

Reading ends when $size - 1 bytes have been read, or a newline or an EOF (whichever comes first).

Tags
throws
Exception
Return values
string

$size bytes of data from the socket

getStatus()

Returns information about the connection.

public getStatus() : array<string|int, mixed>

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
Tags
throws
Exception
Return values
array<string|int, mixed>

Information about existing socket resource.

read()

Returns a specified amount of data.

public read(int $size) : string
Parameters
$size : int

The number of bytes to read from the socket.

Tags
throws
Exception
Return values
string

$size bytes of data from the socket.

startTls()

Start a TLS connection.

public startTls() : bool
Return values
bool

Whether TLS was successfully started.

write()

Writes data to the stream.

public write(string $data) : mixed
Parameters
$data : string

Data to write.

Tags
throws
Exception
Return values
mixed

_checkStream()

Throws an exception is the stream is not a resource.

protected _checkStream() : mixed
Tags
throws
Exception
Return values
mixed

_connect()

Connect to the remote server.

protected _connect(mixed $host, mixed $port, mixed $timeout, mixed $secure, mixed $context, mixed $retries) : mixed
Parameters
$host : mixed
$port : mixed
$timeout : mixed
$secure : mixed
$context : mixed
$retries : mixed
Tags
see
__construct()
throws
Exception
Return values
mixed

Search results