pauseRecv
Description:
void Connection::pauseRecv(void)
Stops the current connection from receiving data. The onMessage callback for this connection will not be triggered. This method is very useful for controlling upload traffic.
Parameters
No parameters
Example
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onConnect = function($connection)
{
// Dynamically add a property to the connection object to keep track of how many requests have been made from the current connection
$connection->messageCount = 0;
};
$worker->onMessage = function(TcpConnection $connection, $data)
{
// Stop receiving data after the connection has received 100 requests
$limit = 100;
if(++$connection->messageCount > $limit)
{
$connection->pauseRecv();
}
};
// Run the worker
Worker::runAll();
See Also
void Connection::resumeRecv(void) Restores the corresponding connection object to receive data again.