Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • Connector
  • DnsConnector
  • LimitingServer
  • SecureConnector
  • SecureServer
  • Server
  • TcpConnector
  • TimeoutConnector
  • UnixConnector

Interfaces

  • ConnectionInterface
  • ConnectorInterface
  • ServerInterface
  • Overview
  • Namespace
  • Class
  • Tree

Class LimitingServer

The LimitingServer decorator wraps a given ServerInterface and is responsible for limiting and keeping track of open connections to this server instance.

Whenever the underlying server emits a connection event, it will check its limits and then either

  • keep track of this connection by adding it to the list of open connections and then forward the connection event
  • or reject (close) the connection when its limits are exceeded and will forward an error event instead.

Whenever a connection closes, it will remove this connection from the list of open connections.

`php $server = new LimitingServer($server, 100); $server->on('connection', function (ConnectionInterface $connection) { $connection->write('hello there!' . PHP_EOL); … }); `

See also the ServerInterface for more details.

Evenement\EventEmitter implements Evenement\EventEmitterInterface uses Evenement\EventEmitterTrait
Extended by React\Socket\LimitingServer implements React\Socket\ServerInterface
Namespace: React\Socket
See: React\Socket\ServerInterface
See: React\Socket\ConnectionInterface
Located at LimitingServer.php
Methods summary
public
# __construct( React\Socket\ServerInterface $server, integer|null $connectionLimit, boolean $pauseOnLimit = false )

Instantiates a new LimitingServer.

Instantiates a new LimitingServer.

You have to pass a maximum number of open connections to ensure the server will automatically reject (close) connections once this limit is exceeded. In this case, it will emit an error event to inform about this and no connection event will be emitted.

`php $server = new LimitingServer($server, 100); $server->on('connection', function (ConnectionInterface $connection) { $connection->write('hello there!' . PHP_EOL); … }); `

You MAY pass a null limit in order to put no limit on the number of open connections and keep accepting new connection until you run out of operating system resources (such as open file handles). This may be useful it you do not want to take care of applying a limit but still want to use the getConnections() method.

You can optionally configure the server to pause accepting new connections once the connection limit is reached. In this case, it will pause the underlying server and no longer process any new connections at all, thus also no longer closing any excessive connections. The underlying operating system is responsible for keeping a backlog of pending connections until its limit is reached, at which point it will start rejecting further connections. Once the server is below the connection limit, it will continue consuming connections from the backlog and will process any outstanding data on each connection. This mode may be useful for some protocols that are designed to wait for a response message (such as HTTP), but may be less useful for other protocols that demand immediate responses (such as a "welcome" message in an interactive chat).

`php $server = new LimitingServer($server, 100, true); $server->on('connection', function (ConnectionInterface $connection) { $connection->write('hello there!' . PHP_EOL); … }); `

Parameters

$server
React\Socket\ServerInterface
$server
$connectionLimit
integer|null
$connectionLimit
$pauseOnLimit
boolean
$pauseOnLimit
public React\Socket\ConnectionInterface[]
# getConnections( )

Returns an array with all currently active connections

Returns an array with all currently active connections

`php foreach ($server->getConnection() as $connection) { $connection->write('Hi!'); } `

Returns

React\Socket\ConnectionInterface[]
public ?string
# getAddress( )

Returns the full address (IP and port) this server is currently listening on

Returns the full address (IP and port) this server is currently listening on

`php $address = $server->getAddress(); echo 'Server listening on ' . $address . PHP_EOL; `

It will return the full address (IP and port) or NULL if it is unknown (not applicable to this server socket or already closed).

If this is a TCP/IP based server and you only want the local port, you may use something like this:

`php $address = $server->getAddress(); $port = parse_url('tcp://' . $address, PHP_URL_PORT); echo 'Server listening on port ' . $port . PHP_EOL; `

Returns

?string
the full listening address (IP and port) or NULL if it is unknown (not applicable to this server socket or already closed)

Implementation of

React\Socket\ServerInterface::getAddress()
public
# pause( )

Pauses accepting new incoming connections.

Pauses accepting new incoming connections.

Removes the socket resource from the EventLoop and thus stop accepting new connections. Note that the listening socket stays active and is not closed.

This means that new incoming connections will stay pending in the operating system backlog until its configurable backlog is filled. Once the backlog is filled, the operating system may reject further incoming connections until the backlog is drained again by resuming to accept new connections.

Once the server is paused, no futher connection events SHOULD be emitted.

`php $server->pause();

$server->on('connection', assertShouldNeverCalled()); `

This method is advisory-only, though generally not recommended, the server MAY continue emitting connection events.

Unless otherwise noted, a successfully opened server SHOULD NOT start in paused state.

You can continue processing events by calling resume() again.

Note that both methods can be called any number of times, in particular calling pause() more than once SHOULD NOT have any effect. Similarly, calling this after close() is a NO-OP.

See

React\Socket\LimitingServer::resume()

Implementation of

React\Socket\ServerInterface::pause()
public
# resume( )

Resumes accepting new incoming connections.

Resumes accepting new incoming connections.

Re-attach the socket resource to the EventLoop after a previous pause().

`php $server->pause();

$loop->addTimer(1.0, function () use ($server) { $server->resume(); }); `

Note that both methods can be called any number of times, in particular calling resume() without a prior pause() SHOULD NOT have any effect. Similarly, calling this after close() is a NO-OP.

See

React\Socket\LimitingServer::pause()

Implementation of

React\Socket\ServerInterface::resume()
public
# close( )

Shuts down this listening socket

Shuts down this listening socket

This will stop listening for new incoming connections on this socket.

Calling this method more than once on the same instance is a NO-OP.

Implementation of

React\Socket\ServerInterface::close()
Methods inherited from Evenement\EventEmitterInterface
emit(), listeners(), on(), once(), removeAllListeners(), removeListener()
Methods used from Evenement\EventEmitterTrait
(), (), (), (), (), ()
Properties used from Evenement\EventEmitterTrait
$listeners
Ratchet API documentation generated by ApiGen 2.8.0