resumeRecv
Description:
void Connection::resumeRecv(void)
Resumes receiving data for the current connection. This method works in conjunction with Connection::pauseRecv and is very useful for controlling upload traffic.
Parameters
No parameters
Example
use Workerman\Worker;
use Workerman\Timer;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onConnect = function(TcpConnection $connection)
{
// Dynamically add a property to the connection object to keep track of how many requests have been received from the current connection
$connection->messageCount = 0;
};
$worker->onMessage = function(TcpConnection $connection, $data)
{
// Stop receiving data after 100 requests per connection
$limit = 100;
if(++$connection->messageCount > $limit)
{
$connection->pauseRecv();
// Resume receiving data after 30 seconds
Timer::add(30, function($connection){
$connection->resumeRecv();
}, array($connection), false);
}
};
// Run the worker
Worker::runAll();
See Also
void Connection::pauseRecv(void) Stops the corresponding connection object from receiving data.