Skip to content

Commit

Permalink
format Swoole demo
Browse files Browse the repository at this point in the history
  • Loading branch information
hhxsv5 committed Jun 16, 2020
1 parent c71ea2c commit f386d7c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/sse-swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

use Hhxsv5\SSE\SSESwoole;
use Hhxsv5\SSE\Update;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

// Swoole SSE Example: push messages to client

$server = new Swoole\Http\Server('0.0.0.0', 5200);
$server = new Server('0.0.0.0', 5200);
$server->set([
'enable_coroutine' => true,
'max_coroutine' => 10000, // worker_num*10000
Expand All @@ -17,7 +20,7 @@
'log_level' => SWOOLE_LOG_WARNING,
'log_file' => __DIR__ . '/swoole.log',
]);
$server->on('Request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($server) {
$server->on('Request', function (Request $request, Response $response) use ($server) {
// $response->header('Access-Control-Allow-Origin', '*');
$response->header('Content-Type', 'text/event-stream');
$response->header('Cache-Control', 'no-cache');
Expand All @@ -33,4 +36,4 @@
return json_encode(compact('news'));
}), 'news');
});
$server->start();
$server->start();

0 comments on commit f386d7c

Please sign in to comment.