-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from basoro/mlite
Update
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,6 @@ plugins/pasien_galleries | |
.env | ||
logs/ | ||
config.php | ||
workerman.php | ||
#workerman.php | ||
composer.lock | ||
backups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
?> |