How to Actively Push Messages
- You can use a timer to push data at regular intervals.
use Workerman\Worker; use Workerman\Timer; use Workerman\Connection\TcpConnection; require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:1234');
// After the process starts, push data to clients at regular intervals.
$worker->onWorkerStart = function($worker){
Timer::add(1, function() use($worker){
foreach($worker->connections as $connection) {
$connection->send('hello');
}
});
};
Worker::runAll();
2. Notify Workerman to push data when a certain event occurs in another project.
See [Common Issues - Pushing in Other Projects](push-in-other-project.html)