Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
73c4a21
try to add basic websocket support
albertcht Feb 25, 2018
dc999cd
modify event fire arguments
albertcht Feb 25, 2018
b7d19e3
delete unnecessary unset
albertcht Feb 25, 2018
ab8d8ee
remove onClose event from http server
albertcht Feb 25, 2018
be1bd85
clear events instance in worker start in case of repeated listeners i…
albertcht Feb 26, 2018
8766265
add facade namespace
albertcht Feb 26, 2018
3ab1119
delete redundant code
albertcht Feb 26, 2018
1b3b07a
add more dedug info to infos command
albertcht Feb 26, 2018
d2808f3
add table room for websockets
albertcht Mar 4, 2018
2572834
add swoole_websocket.php config file
albertcht Mar 4, 2018
6927b9d
midify default room_rows
albertcht Mar 4, 2018
0fd9c7e
set websocket while server started
albertcht Mar 4, 2018
1cf9d6e
improve table room
albertcht Mar 4, 2018
38e2341
add type hinting to the rest of table room
albertcht Mar 4, 2018
327868d
catch and log error while on request
albertcht Mar 4, 2018
6446b44
improve 500 response while on request
albertcht Mar 4, 2018
2645988
implement partial websocket feature
albertcht Apr 13, 2018
71f1274
implement in function for websocket
albertcht Apr 13, 2018
a4efc89
try to fix pecl install
albertcht Apr 13, 2018
381e9fd
add websocket formatter
albertcht Apr 13, 2018
53bb54a
improve pushMessage for websocket
albertcht Apr 13, 2018
132196f
install PHPUnitPrettyResultPrinter
albertcht Apr 13, 2018
0abbf3c
move canWebsocket
albertcht Apr 14, 2018
1a78a51
refactor websocket
albertcht Apr 14, 2018
3370c35
fix namespace
albertcht Apr 14, 2018
db8cc6b
reuqire php 7.1
albertcht Apr 14, 2018
a15cee3
update composer.json
albertcht Apr 14, 2018
ea8e1c2
fix typo
albertcht Apr 14, 2018
b312ba0
force json_decode to array in default formatter
albertcht Apr 14, 2018
31f3b9f
fix load sequence of websocket instance
albertcht Apr 14, 2018
e194417
enhance code
albertcht Apr 14, 2018
cf7567e
add facades for room and websocket
albertcht Apr 14, 2018
aaf9300
move websocket namespace to an upper layer
albertcht Apr 14, 2018
09f6f52
add swoole server facade
albertcht Apr 14, 2018
8959c2e
fix namespace
albertcht Apr 14, 2018
ad8e962
try to add table
albertcht Apr 14, 2018
d135a3a
return this for add function of Table
albertcht Apr 14, 2018
237b7b5
comment example settings for tables
albertcht Apr 14, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ sudo: false

matrix:
include:
- php: 7.0
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/framework:5.2.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/framework:5.3.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/framework:5.4.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/framework:5.5.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.1.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.2.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.3.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.4.*
- php: 7.0
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
- php: 7.1
Expand Down Expand Up @@ -66,10 +46,10 @@ matrix:
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.*

before_install:
- pecl install swoole
- printf "\n" | pecl install swoole

install:
- composer require "${FRAMEWORK_VERSION}" --no-update -n
- travis_retry composer install --no-suggest --prefer-dist -n -o

script: vendor/bin/phpunit
script: vendor/bin/phpunit
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
}
],
"require": {
"php": "^7.1",
"illuminate/console": "~5.1",
"illuminate/contracts": "~5.1",
"illuminate/http": "~5.1",
"illuminate/support": "~5.1"
},
"require-dev": {
"laravel/lumen-framework": "~5.1",
"phpunit/phpunit": "~6.0"
"phpunit/phpunit": "^6.1",
"mockery/mockery": "~1.0",
"codedungeon/phpunit-result-printer": "^0.14.0"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 30 additions & 1 deletion config/swoole_http.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Swoole\Table;

return [
/*
|--------------------------------------------------------------------------
Expand All @@ -15,10 +17,37 @@
'options' => [
'pid_file' => env('SWOOLE_HTTP_PID_FILE', base_path('storage/logs/swoole_http.pid')),
'log_file' => env('SWOOLE_HTTP_LOG_FILE', base_path('storage/logs/swoole_http.log')),
'daemonize' => env('SWOOLE_HTTP_DAEMONIZE', 0),
'daemonize' => env('SWOOLE_HTTP_DAEMONIZE', false),
'task_worker_num' => env('SWOOLE_HTTP_TASK_WORKER_NUM', 4)
],
],

'websocket' => [
'enabled' => env('SWOOLE_HTTP_WEBSOCKET', false),
],

/*
|--------------------------------------------------------------------------
| Providers here will be registered on every request.
|--------------------------------------------------------------------------
*/
'providers' => [
// App\Providers\AuthServiceProvider::class,
],

/*
|--------------------------------------------------------------------------
| Define your swoole tables here.
|
| @see https://wiki.swoole.com/wiki/page/p-table.html
|--------------------------------------------------------------------------
*/
'tables' => [
// 'table_name' => [
// 'size' => 1024,
// 'columns' => [
// ['name' => 'column_name', 'type' => Table::TYPE_STRING, 'size' => 1024],
// ]
// ],
]
];
59 changes: 59 additions & 0 deletions config/swoole_websocket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Websocket handler for onOpen and onClose callback
| Replace this handler before you start it
|--------------------------------------------------------------------------
*/
'handler' => SwooleTW\Http\Websocket\WebsocketHandler::class,

/*
|--------------------------------------------------------------------------
| Websocket handlers mapping for onMessage callback
|--------------------------------------------------------------------------
*/
'handlers' => [
// 'event_name' => 'App\Handlers\ExampleHandler@function',
],

/*
|--------------------------------------------------------------------------
| Default websocket driver
|--------------------------------------------------------------------------
*/
'default' => 'table',

/*
|--------------------------------------------------------------------------
| Default message formatter
| Replace it if you want to customize your websocket payload
|--------------------------------------------------------------------------
*/
'formatter' => SwooleTW\Http\Websocket\Formatters\DefaultFormatter::class,

/*
|--------------------------------------------------------------------------
| Drivers mapping
|--------------------------------------------------------------------------
*/
'drivers' => [
'table' => SwooleTW\Http\Websocket\Rooms\TableRoom::class,
],

/*
|--------------------------------------------------------------------------
| Drivers settings
|--------------------------------------------------------------------------
*/
'settings' => [

'table' => [
'room_rows' => 4096,
'room_size' => 2048,
'client_rows' => 8192,
'client_size' => 2048
]
],
];
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
<testsuites>
<testsuite name="Laravel Swoole Http Test Suite">
<directory suffix="Test.php">./tests</directory>
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/HttpServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,21 @@ protected function showInfos()
{
$pid = $this->getPid();
$isRunning = $this->isRunning($pid);
$host = $this->configs['server']['host'];
$port = $this->configs['server']['port'];
$isWebsocket = $this->configs['websocket']['enabled'];
$logFile = $this->configs['server']['options']['log_file'];

$this->table(['Name', 'Value'], [
['PHP Version', 'Version' => phpversion()],
['Swoole Version', 'Version' => swoole_version()],
['Laravel Version', $this->getApplication()->getVersion()],
['Server Status', $isRunning ? 'Online' : 'Offline'],
['Listen IP', $host],
['Listen Port', $port],
['Websocket Mode', $isWebsocket ? 'On' : 'Off'],
['PID', $isRunning ? $pid : 'None'],
['Log Path', $logFile],
]);
}

Expand Down
10 changes: 6 additions & 4 deletions src/HttpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace SwooleTW\Http;

use SwooleTW\Http\Commands\HttpServerCommand;
use Illuminate\Support\ServiceProvider;
use SwooleTW\Http\Commands\HttpServerCommand;

abstract class HttpServiceProvider extends ServiceProvider
{
Expand All @@ -21,7 +21,7 @@ abstract class HttpServiceProvider extends ServiceProvider
*/
public function register()
{
$this->mergeConfig();
$this->mergeConfigs();
$this->registerManager();
$this->registerCommands();
}
Expand All @@ -41,16 +41,18 @@ abstract protected function registerManager();
public function boot()
{
$this->publishes([
__DIR__ . '/../config/swoole_http.php' => base_path('config/swoole_http.php')
__DIR__ . '/../config/swoole_http.php' => base_path('config/swoole_http.php'),
__DIR__ . '/../config/swoole_websocket.php' => base_path('config/swoole_websocket.php')
], 'config');
}

/**
* Merge configurations.
*/
protected function mergeConfig()
protected function mergeConfigs()
{
$this->mergeConfigFrom(__DIR__ . '/../config/swoole_http.php', 'swoole_http');
$this->mergeConfigFrom(__DIR__ . '/../config/swoole_websocket.php', 'swoole_websocket');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Server/Facades/Server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SwooleTW\Http\Server\Facades;

use Illuminate\Support\Facades\Facade;

class Server extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'swoole.server';
}
}
18 changes: 18 additions & 0 deletions src/Server/Facades/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SwooleTW\Http\Server\Facades;

use Illuminate\Support\Facades\Facade;

class Table extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'swoole.table';
}
}
Loading