Wrench\Server¶
-
class
Server
¶ WebSocket server
The server extends socket, which provides the master socket resource. This resource is listened to, and an array of clients managed.
-
constant
EVENT_SOCKET_CONNECT
¶ Events
-
property
uri
¶ protected string
The URI of the server
-
property
options
¶ protected array
Options
-
property
logger
¶ protected Closure
A logging callback
The default callback simply prints to stdout. You can pass your own logger in the options array. It should take a string message and string priority as parameters.
-
property
listeners
¶ protected array<string
Event listeners
Add listeners using the addListener() method.
-
property
connectionManager
¶ protected ConnectionManager
Connection manager
-
property
applications
¶ protected array<string
Applications
-
property
protocol
¶ protected Protocol
-
__construct
($uri, $options = array())¶ Constructor
Parameters: - $uri (string) – Websocket URI, e.g. ws://localhost:8000/, path will be ignored
- $options (array) – (optional) See configure
-
configure
($options)¶ Configure options
Options include - socket_class => The socket class to use, defaults to ServerSocket - socket_options => An array of socket options - logger => Closure($message, $priority = ‘info’), used for logging
Parameters: - $options (array) –
Returns: void
-
configureLogger
()¶ Configures the logger
Returns: void
-
configureConnectionManager
()¶ Configures the connection manager
Returns: void
-
getConnectionManager
()¶ Gets the connection manager
Returns: WrenchConnectionManager
-
getUri
()¶ Returns: string
-
setLogger
($logger)¶ Sets a logger
Parameters: - $logger (Closure) –
Returns: void
-
run
()¶ Main server loop
Returns: void This method does not return!
-
log
($message, $priority = 'info')¶ Logs a message to the server log
The default logger simply prints the message to stdout. You can provide a logging closure. This is useful, for instance, if you’ve daemonized and closed STDOUT.
Parameters: - $message (string) – Message to display.
- $priority –
Returns: void
-
notify
($event, $arguments = array())¶ Notifies listeners of an event
Parameters: - $event (string) –
- $arguments (array) – Event arguments
Returns: void
-
addListener
($event, $callback)¶ Adds a listener
Provide an event (see the Server::EVENT_* constants) and a callback closure. Some arguments may be provided to your callback, such as the connection the caused the event.
Parameters: - $event (string) –
- $callback (Closure) –
Returns: void
-
getApplication
($key)¶ Returns a server application.
Parameters: - $key (string) – Name of application.
Returns: Application The application object.
-
registerApplication
($key, $application)¶ Adds a new application object to the application storage.
Parameters: - $key (string) – Name of application.
- $application (object) – The application object
Returns: void
-
configureProtocol
()¶ Configures the protocol option
-
constant