From e0a19463fd3fd8c8aef1ce3cfbec6932d3cf1d07 Mon Sep 17 00:00:00 2001 From: Basoro Date: Wed, 16 Oct 2024 15:50:03 +0800 Subject: [PATCH] Update --- .gitignore | 2 +- workerman.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 workerman.php 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