diff --git a/.gitignore b/.gitignore index 651e35da3..3df97cf99 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,6 @@ plugins/pasien_galleries .env logs/ config.php -workerman.php +#workerman.php composer.lock backups diff --git a/workerman.php b/workerman.php new file mode 100644 index 000000000..1baeefa02 --- /dev/null +++ b/workerman.php @@ -0,0 +1,38 @@ +onConnect = function($connection){ + $remote_ip = $connection->getRemoteIp(); + + $connection->onWebSocketConnect = function($connection) use ($remote_ip){ + print("$remote_ip - Berhasil terhubung\n"); + unset($remote_ip); + }; + }; + + + // Jika ada yang mengirim data + $ws->onMessage = function($connection, $data) use($ws){ + + // Broadcast datanya ke semua yang terhubung + foreach($ws->connections as $connection_sub){ + $connection_sub->send($data); + } + + }; + + // Jika terputus + $ws->onClose = function($connection){ + $remote_ip = $connection->getRemoteIp(); + print("$remote_ip - Telah terputus!\n"); + }; + + + Worker::runAll(); + +?> \ No newline at end of file