websocket.php
972 字节
<?php
use Illuminate\Http\Request;
use SwooleTW\Http\Websocket\Facades\Websocket;
/*
|--------------------------------------------------------------------------
| Websocket Routes
|--------------------------------------------------------------------------
|
| Here is where you can register websocket events for your application.
|
*/
Websocket::on('connect', function ($websocket, Request $request) {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(1111111, true) . PHP_EOL, FILE_APPEND);
// called while socket on connect
});
Websocket::on('disconnect', function ($websocket) {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(22222, true) . PHP_EOL, FILE_APPEND);
// called while socket on disconnect
});
Websocket::on('example', function ($websocket, $data) {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(3333, true) . PHP_EOL, FILE_APPEND);
$websocket->emit('message', $data);
});