IMuSession

require_once IMu::$lib . '/Session.php';

Since: 1.0

Description

Manages a connection to an IMu server.

The server’s host name and port can be specified by setting properties on the object or by setting class-based default properties.

Examples

  1. Connect to a default server.
$session = new IMuSession();
$session->connect();

Class Properties

Property

Details

defaultHost

The default host to connect to if no object-specific host has been supplied.

Type:

string

Getter:

string getDefaultHost()

Setter:

setDefaultHost(string $value)

defaultPort

The number of the port used to create a connection if no object-specific host has been supplied.

Type:

int

Getter:

int getDefaultPort()

Setter:

setDefaultPort(int $value)

defaultTimeout

The default timeout value (in seconds). This timeout is used if the constructor is called without a timeout argument.

Type:

int

Getter:

int getDefaultTimeout()

Setter:

setDefaultTimeout(int $value)

Constructors

Constructor

Details

__construct($host, $port, $timeout)

__construct([string $host = null [, string $port = null [, int $timeout = null]]])

Creates a Session object with the specified host and port.

Parameters:

$host (string)

The default server host. Defaults to null if not supplied.

$port (string)

The default server port. Defaults to null if not supplied.

$timeout (int)

The default timeout value (in seconds). Defaults to null if not supplied.

Properties

Property

Details

close

A flag controlling whether the connection to the server should be closed after the next request. This flag is passed to the server as part of the next request to allow it to clean up.

Type:

bool

Getter:

bool getClose()

Setter:

setClose(bool $value)

context

The unique identifier assigned by the server to the current session.

Type:

string

Getter:

string getContext()

Setter:

setContext(string $value)

host

The name of the host used to create the connection. Setting this property after the connection has been established has no effect.

Type:

string

Getter:

string getHost()

Setter:

setHost(string $value)

port

The number of the port used to create the connection. Setting this property after the connection has been established has no effect.

Type:

int

Getter:

int getPort()

Setter:

setPort(int $value)

suspend

A flag controlling whether the server process handling this session should begin listening on a distinct, process-specific port to ensure a new session connects to the same server process.

This is part of IMu's mechanism for maintaining state. If this flag is set to true, then after the next request is made to the server, the IMuSession's port property will be altered to the process-specific port number.

Type:

bool

Getter:

bool getSuspend()

Setter:

setSuspend(bool $value)

timeout

Type:

int

Getter:

int getTimeout()

Setter:

setTimeout(int $value)

Methods

Method

Details

connect()

connect()

Opens a connection to an IMu server.

Returns:

Throws:

IMuException

The connection could not be opened.

disconnect()

disconnect()

Closes the connection to the IMu server.

Returns:

login($login, $password, $spawn)

login(string $login [, string $password = null [, bool $spawn = true]])

Logs in as the given user with the given password.

If the $spawn parameter is set to true, this will cause the server to create a new child process specifically to handle the newly logged in user's requests.

Parameters:

$login (string)

The name of the user to login as.

$password (string)

The user's password for authentication. Defaults to null if not supplied.

$spawn (bool)

A flag indicating whether the process should create a new child process specifically for handling the newly logged in user's requests. This value defaults to true.

Defaults to true if not supplied.

Returns:

Throws:

IMuException

The login request failed.

Exception

A low-level socket communication error occurred.

logout()

logout()

Logs the user out of the server.

Returns:

request($request)

array request(array $request)

Submits a low-level request to the IMu server.

Parameters:

$request (array)

An associative array containing the request parameters.

Returns:

array

An associative array containing the server's response.

Throws:

IMuException

A server-side error occurred.