how manage buffering data when sending data to clients by ratchetphp
I implemented a websocket server in php by ratchetphp and [reactphp](https://github.com/reactphp/react) libraries.

I want to send data to clients which is 10MB in size and can't be more reduced. But the problem is where the data should be buffered first and till client don't receives data completely, the buffer would not go off. Downloading the data about 10MB could take 2-3minutes for each client and every 2 seconds we have new data comming in to be added to cleint's buffer. So the size of buffer gets too much and scripts needs more RAM to do it and it crashes.

I want to know how to check buffer before each time I'm sending information to clients to be aware of does it received the data completely. I also want to check that the buffer is free at the moment or not so if it is not in free state then I would not send it new pack of data.

Even if I could disable buffer at all and send data to clients instantly, it would be best.

this is my code:

```
global $port,$clients;
$port = 9000;
$clients = [];


class arzWebSocketClients implements Ratchet\MessageComponentInterface {

    public function __construct() {

    }

    public function onOpen(Ratchet\ConnectionInterface $conn) {

        $clients[$conn->resourceId] = $conn;

    }

    public function onMessage(Ratchet\ConnectionInterface $from, $msg) {

    }

    public function onClose(Ratchet\ConnectionInterface $conn) {
        global $clients;
        unset($clients[$conn->resourceId]);

    }

    public function onError(Ratchet\ConnectionInterface $conn, \Exception $e) {
        global $clients;
        unset($clients[$conn->resourceId]);

        $conn->close();

    }

}

//-----------------------------------------------------------------

$loop = \React\EventLoop\Factory::create();

$loop->addPeriodicTimer(2, function ($timer) use ($loop) {


    global $clients;

    $jsonedData = json_encode($data); //----- about 10 MegaBytes

    foreach ($clients as $a){


        $a->send($jsonedData);


    }

});
//-----------------------------------------------------------------
$app = new Ratchet\App('localhost', $port,'0.0.0.0',$loop);
$app->route('/', new arzWebSocketClients);
$app->run();
```