Skip to content

Commit

Permalink
Merge pull request #245 from basoro/mlite
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
basoro authored Oct 16, 2024
2 parents e5d283a + e0a1946 commit 15b6b25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ plugins/pasien_galleries
.env
logs/
config.php
workerman.php
#workerman.php
composer.lock
backups
38 changes: 38 additions & 0 deletions workerman.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php' ;

# port 3892 terserah mau diganti apa
$ws = new Worker('websocket://0.0.0.0:3892');

// Jika ada yang terhubung
$ws->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();

?>

0 comments on commit 15b6b25

Please sign in to comment.