Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 9dff9d1

Browse files
authored
Merge pull request #140 from swooletw/develop
Develop
2 parents 7c11d75 + 572d7f9 commit 9dff9d1

File tree

70 files changed

+3892
-1035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3892
-1035
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Files
2+
.DS_Store
23
phpunit.xml
34
composer.lock
45

.travis.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ sudo: false
44

55
matrix:
66
include:
7-
- php: 7.1
8-
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
9-
- php: 7.1
10-
env: FRAMEWORK_VERSION=laravel/framework:5.2.*
11-
- php: 7.1
12-
env: FRAMEWORK_VERSION=laravel/framework:5.3.*
13-
- php: 7.1
14-
env: FRAMEWORK_VERSION=laravel/framework:5.4.*
15-
- php: 7.1
16-
env: FRAMEWORK_VERSION=laravel/framework:5.5.*
17-
- php: 7.1
18-
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.1.*
19-
- php: 7.1
20-
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.2.*
21-
- php: 7.1
22-
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.3.*
23-
- php: 7.1
24-
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.4.*
25-
- php: 7.1
26-
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.*
277
- php: 7.2
288
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
299
- php: 7.2
@@ -52,4 +32,9 @@ install:
5232
- composer require "${FRAMEWORK_VERSION}" --no-update -n
5333
- travis_retry composer install --no-suggest --prefer-dist -n -o
5434

55-
script: vendor/bin/phpunit
35+
script:
36+
- mkdir -p build/logs
37+
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
38+
39+
after_success:
40+
- vendor/bin/coveralls -v

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
"require-dev": {
2525
"laravel/lumen-framework": "~5.1",
2626
"phpunit/phpunit": "^6.1",
27+
"phpunit/php-code-coverage": "^5.2",
28+
"satooshi/php-coveralls": "^1.0",
2729
"mockery/mockery": "~1.0",
28-
"codedungeon/phpunit-result-printer": "^0.14.0"
30+
"codedungeon/phpunit-result-printer": "^0.14.0",
31+
"php-mock/php-mock": "^2.0"
2932
},
3033
"autoload": {
3134
"files": [

config/swoole_http.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
'public_path' => base_path('public'),
1818
// Determine if to use swoole to respond request for static files
1919
'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true),
20+
// You must add --enable-openssl while compiling Swoole
21+
// Put `SWOOLE_SOCK_TCP | SWOOLE_SSL` if you want to enable SSL
22+
'socket_type' => SWOOLE_SOCK_TCP,
2023
'options' => [
2124
'pid_file' => env('SWOOLE_HTTP_PID_FILE', base_path('storage/logs/swoole_http.pid')),
2225
'log_file' => env('SWOOLE_HTTP_LOG_FILE', base_path('storage/logs/swoole_http.log')),
@@ -31,7 +34,7 @@
3134
'buffer_output_size' => 10 * 1024 * 1024,
3235
// Max buffer size for socket connections
3336
'socket_buffer_size' => 128 * 1024 * 1024,
34-
// Worker will restart after processing this number of request
37+
// Worker will restart after processing this number of requests
3538
'max_request' => 3000,
3639
// Enable coroutine send
3740
'send_yield' => true,
@@ -57,6 +60,17 @@
5760
*/
5861
'ob_output' => env('SWOOLE_OB_OUTPUT', true),
5962

63+
/*
64+
|--------------------------------------------------------------------------
65+
| Pre-resolved instances here will be resolved when sandbox created.
66+
|--------------------------------------------------------------------------
67+
*/
68+
'pre_resolved' => [
69+
'view', 'files', 'session', 'session.store', 'routes',
70+
'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookie',
71+
'encrypter', 'hash', 'router', 'translator', 'url', 'log',
72+
],
73+
6074
/*
6175
|--------------------------------------------------------------------------
6276
| Instances here will be cleared on every request.
@@ -75,6 +89,23 @@
7589
Illuminate\Pagination\PaginationServiceProvider::class,
7690
],
7791

92+
/*
93+
|--------------------------------------------------------------------------
94+
| Resetters for sandbox app.
95+
|--------------------------------------------------------------------------
96+
*/
97+
'resetters' => [
98+
SwooleTW\Http\Server\Resetters\ResetConfig::class,
99+
SwooleTW\Http\Server\Resetters\ResetSession::class,
100+
SwooleTW\Http\Server\Resetters\ResetCookie::class,
101+
SwooleTW\Http\Server\Resetters\ClearInstances::class,
102+
SwooleTW\Http\Server\Resetters\BindRequest::class,
103+
SwooleTW\Http\Server\Resetters\RebindKernelContainer::class,
104+
SwooleTW\Http\Server\Resetters\RebindRouterContainer::class,
105+
SwooleTW\Http\Server\Resetters\RebindViewContainer::class,
106+
SwooleTW\Http\Server\Resetters\ResetProviders::class,
107+
],
108+
78109
/*
79110
|--------------------------------------------------------------------------
80111
| Define your swoole tables here.

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@
2525
<directory suffix=".php">./src</directory>
2626
</whitelist>
2727
</filter>
28+
<php>
29+
<const name="IN_PHPUNIT" value="true"/>
30+
</php>
2831
</phpunit>

src/Commands/HttpServerCommand.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace SwooleTW\Http\Commands;
44

5-
use Illuminate\Console\Command;
5+
use Throwable;
66
use Swoole\Process;
7+
use Illuminate\Console\Command;
78

9+
/**
10+
* @codeCoverageIgnore
11+
*/
812
class HttpServerCommand extends Command
913
{
1014
/**
@@ -92,7 +96,7 @@ protected function start()
9296
'swoole_http_server process is running: ps aux|grep "swoole")');
9397
}
9498

95-
$this->laravel->make('swoole.http')->run();
99+
$this->laravel->make('swoole.manager')->run();
96100
}
97101

98102
/**
@@ -229,9 +233,11 @@ protected function isRunning($pid)
229233
return false;
230234
}
231235

232-
Process::kill($pid, 0);
233-
234-
return ! swoole_errno();
236+
try {
237+
return Process::kill($pid, 0);
238+
} catch (Throwable $e) {
239+
return false;
240+
}
235241
}
236242

237243
/**
@@ -322,9 +328,14 @@ protected function isDaemon()
322328
protected function checkEnvironment()
323329
{
324330
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
325-
throw new \RuntimeException("Swoole extension doesn't support Windows OS yet.");
331+
$this->error("Swoole extension doesn't support Windows OS yet.");
332+
exit;
326333
} elseif (! extension_loaded('swoole')) {
327-
throw new \RuntimeException("Can't detect Swoole extension installed.");
334+
$this->error("Can't detect Swoole extension installed.");
335+
exit;
336+
} elseif (! version_compare(swoole_version(), '4.0.0', 'ge')) {
337+
$this->error("Your Swoole version must be higher than 4.0 to use coroutine.");
338+
exit;
328339
}
329340
}
330341
}

src/Table/CanSwooleTable.php renamed to src/Concerns/InteractsWithSwooleTable.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace SwooleTW\Http\Table;
3+
namespace SwooleTW\Http\Concerns;
44

55
use Swoole\Table;
66
use SwooleTW\Http\Table\SwooleTable;
77

8-
trait CanSwooleTable
8+
trait InteractsWithSwooleTable
99
{
1010
/**
1111
* @var \SwooleTW\Http\Server\Table
@@ -49,8 +49,9 @@ protected function registerTables()
4949
*/
5050
protected function bindSwooleTable()
5151
{
52-
$this->app->singleton('swoole.table', function () {
52+
$this->app->singleton(SwooleTable::class, function () {
5353
return $this->table;
5454
});
55+
$this->app->alias(SwooleTable::class, 'swoole.table');
5556
}
5657
}

0 commit comments

Comments
 (0)