PHP Класс Resque\Socket\Server

Автор: Michael Haynes ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$clients The connected clients.
$config Configuration information used by the server.
$events Dictionary of events and the callbacks attached to them.
$logger Monolog logger interface
$max_clients The maximum number of clients allowed to connect.
$max_read The maximum number of bytes to read from a socket at a single time.
$shutdown True if on the next iteration, the server should shutdown.
$socket The socket used by the server.
$started if the server has started
$tv_sec Connection timeout

Открытые методы

Метод Описание
__construct ( array $config, Logger $logger ) Creates the socket and starts listening to it.
__toString ( ) : string Generate a string representation of this server.
close ( ) Closes the socket on shutdown
disconnect ( Client $client, string $message = 'Goodbye.' ) : mixed Disconnect a client
fire ( string $event, Client &$client, mixed $data = null ) : true Raise a given event with the supplied data.
forget ( string $event, mixed $callback ) : true Deletes a function from the call list for a certain action
fwrite ( resource $fh, string $string ) Write a string to a resource
listen ( string $event, mixed $callback ) : true Adds a function to be called whenever a certain action happens
log ( ) Send log message to logger
onConnect ( mixed $callback ) : mixed Helper function to make using connect event easier
onDisconnect ( mixed $callback ) : mixed Helper function to make using disconnect event easier
onReceive ( mixed $callback ) : mixed Helper function to make using receive event easier
run ( ) Runs the server code until the server is shut down.
send ( Client &$client, string $message, string $end = true ) : mixed Writes data to the socket, including the length of the data, and ends it with a CRLF unless specified.
shutdown ( ) Schedule a shutdown. Will finish processing the current run.
start ( ) Starts the server

Описание методов

__construct() публичный Метод

Creates the socket and starts listening to it.
public __construct ( array $config, Logger $logger )
$config array Array of configuration options
$logger Resque\Logger Output logger

__toString() публичный Метод

Generate a string representation of this server.
public __toString ( ) : string
Результат string String identifier for this server instance.

close() публичный Метод

Closes the socket on shutdown
public close ( )

disconnect() публичный Метод

Disconnect a client
public disconnect ( Client $client, string $message = 'Goodbye.' ) : mixed
$client Client The client to disconnect
$message string Data to write to the socket.
Результат mixed

fire() публичный Метод

Raise a given event with the supplied data.
public fire ( string $event, Client &$client, mixed $data = null ) : true
$event string Name of event to be raised.
$client Client Connected client
$data mixed Optional, any data that should be passed to each callback.
Результат true

forget() публичный Метод

Deletes a function from the call list for a certain action
public forget ( string $event, mixed $callback ) : true
$event string Name of event.
$callback mixed The callback as defined when listen() was called.
Результат true

fwrite() публичный статический Метод

Write a string to a resource
public static fwrite ( resource $fh, string $string )
$fh resource The resource to write to
$string string The string to write

listen() публичный Метод

Adds a function to be called whenever a certain action happens
public listen ( string $event, mixed $callback ) : true
$event string Name of event to listen on.
$callback mixed Any callback callable by call_user_func_array.
Результат true

log() публичный Метод

Send log message to logger
public log ( )

onConnect() публичный Метод

Helper function to make using connect event easier
public onConnect ( mixed $callback ) : mixed
$callback mixed Any callback callable by call_user_func_array.
Результат mixed

onDisconnect() публичный Метод

Helper function to make using disconnect event easier
public onDisconnect ( mixed $callback ) : mixed
$callback mixed Any callback callable by call_user_func_array.
Результат mixed

onReceive() публичный Метод

Helper function to make using receive event easier
public onReceive ( mixed $callback ) : mixed
$callback mixed Any callback callable by call_user_func_array.
Результат mixed

run() публичный Метод

Runs the server code until the server is shut down.
public run ( )

send() публичный Метод

It is perfectly valid for socket_write to return zero which means no bytes have been written. Be sure to use the === operator to check for FALSE in case of an error.
public send ( Client &$client, string $message, string $end = true ) : mixed
$client Client Connected client to write to
$message string Data to write to the socket.
$end string Data to end the line with. Specify false if you don't want a line end sent.
Результат mixed Returns the number of bytes successfully written to the socket or FALSE on failure. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.

shutdown() публичный Метод

Schedule a shutdown. Will finish processing the current run.
public shutdown ( )

start() публичный Метод

Starts the server
public start ( )

Описание свойств

$clients защищенное свойство

The connected clients.
protected $clients

$config защищенное свойство

Configuration information used by the server.
protected $config

$events защищенное свойство

Dictionary of events and the callbacks attached to them.
protected $events

$logger защищенное свойство

Monolog logger interface
protected $logger

$max_clients защищенное свойство

The maximum number of clients allowed to connect.
protected $max_clients

$max_read защищенное свойство

The maximum number of bytes to read from a socket at a single time.
protected $max_read

$shutdown защищенное свойство

True if on the next iteration, the server should shutdown.
protected $shutdown

$socket защищенное свойство

The socket used by the server.
protected $socket

$started защищенное свойство

if the server has started
protected $started

$tv_sec защищенное свойство

Connection timeout
protected $tv_sec