Skip to content

Commit

Permalink
Merge pull request swooletw#140 from swooletw/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
albertcht authored Sep 4, 2018
2 parents 7c11d75 + 572d7f9 commit 9dff9d1
Show file tree
Hide file tree
Showing 70 changed files with 3,892 additions and 1,035 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Files
.DS_Store
phpunit.xml
composer.lock

Expand Down
27 changes: 6 additions & 21 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.1
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/framework:5.2.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/framework:5.3.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/framework:5.4.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/framework:5.5.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.1.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.2.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.3.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.4.*
- php: 7.1
env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.*
- php: 7.2
env: FRAMEWORK_VERSION=laravel/framework:5.1.*
- php: 7.2
Expand Down Expand Up @@ -52,4 +32,9 @@ install:
- composer require "${FRAMEWORK_VERSION}" --no-update -n
- travis_retry composer install --no-suggest --prefer-dist -n -o

script: vendor/bin/phpunit
script:
- mkdir -p build/logs
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_success:
- vendor/bin/coveralls -v
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"require-dev": {
"laravel/lumen-framework": "~5.1",
"phpunit/phpunit": "^6.1",
"phpunit/php-code-coverage": "^5.2",
"satooshi/php-coveralls": "^1.0",
"mockery/mockery": "~1.0",
"codedungeon/phpunit-result-printer": "^0.14.0"
"codedungeon/phpunit-result-printer": "^0.14.0",
"php-mock/php-mock": "^2.0"
},
"autoload": {
"files": [
Expand Down
33 changes: 32 additions & 1 deletion config/swoole_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
'public_path' => base_path('public'),
// Determine if to use swoole to respond request for static files
'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true),
// You must add --enable-openssl while compiling Swoole
// Put `SWOOLE_SOCK_TCP | SWOOLE_SSL` if you want to enable SSL
'socket_type' => SWOOLE_SOCK_TCP,
'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')),
Expand All @@ -31,7 +34,7 @@
'buffer_output_size' => 10 * 1024 * 1024,
// Max buffer size for socket connections
'socket_buffer_size' => 128 * 1024 * 1024,
// Worker will restart after processing this number of request
// Worker will restart after processing this number of requests
'max_request' => 3000,
// Enable coroutine send
'send_yield' => true,
Expand All @@ -57,6 +60,17 @@
*/
'ob_output' => env('SWOOLE_OB_OUTPUT', true),

/*
|--------------------------------------------------------------------------
| Pre-resolved instances here will be resolved when sandbox created.
|--------------------------------------------------------------------------
*/
'pre_resolved' => [
'view', 'files', 'session', 'session.store', 'routes',
'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookie',
'encrypter', 'hash', 'router', 'translator', 'url', 'log',
],

/*
|--------------------------------------------------------------------------
| Instances here will be cleared on every request.
Expand All @@ -75,6 +89,23 @@
Illuminate\Pagination\PaginationServiceProvider::class,
],

/*
|--------------------------------------------------------------------------
| Resetters for sandbox app.
|--------------------------------------------------------------------------
*/
'resetters' => [
SwooleTW\Http\Server\Resetters\ResetConfig::class,
SwooleTW\Http\Server\Resetters\ResetSession::class,
SwooleTW\Http\Server\Resetters\ResetCookie::class,
SwooleTW\Http\Server\Resetters\ClearInstances::class,
SwooleTW\Http\Server\Resetters\BindRequest::class,
SwooleTW\Http\Server\Resetters\RebindKernelContainer::class,
SwooleTW\Http\Server\Resetters\RebindRouterContainer::class,
SwooleTW\Http\Server\Resetters\RebindViewContainer::class,
SwooleTW\Http\Server\Resetters\ResetProviders::class,
],

/*
|--------------------------------------------------------------------------
| Define your swoole tables here.
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<const name="IN_PHPUNIT" value="true"/>
</php>
</phpunit>
25 changes: 18 additions & 7 deletions src/Commands/HttpServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace SwooleTW\Http\Commands;

use Illuminate\Console\Command;
use Throwable;
use Swoole\Process;
use Illuminate\Console\Command;

/**
* @codeCoverageIgnore
*/
class HttpServerCommand extends Command
{
/**
Expand Down Expand Up @@ -92,7 +96,7 @@ protected function start()
'swoole_http_server process is running: ps aux|grep "swoole")');
}

$this->laravel->make('swoole.http')->run();
$this->laravel->make('swoole.manager')->run();
}

/**
Expand Down Expand Up @@ -229,9 +233,11 @@ protected function isRunning($pid)
return false;
}

Process::kill($pid, 0);

return ! swoole_errno();
try {
return Process::kill($pid, 0);
} catch (Throwable $e) {
return false;
}
}

/**
Expand Down Expand Up @@ -322,9 +328,14 @@ protected function isDaemon()
protected function checkEnvironment()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
throw new \RuntimeException("Swoole extension doesn't support Windows OS yet.");
$this->error("Swoole extension doesn't support Windows OS yet.");
exit;
} elseif (! extension_loaded('swoole')) {
throw new \RuntimeException("Can't detect Swoole extension installed.");
$this->error("Can't detect Swoole extension installed.");
exit;
} elseif (! version_compare(swoole_version(), '4.0.0', 'ge')) {
$this->error("Your Swoole version must be higher than 4.0 to use coroutine.");
exit;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace SwooleTW\Http\Table;
namespace SwooleTW\Http\Concerns;

use Swoole\Table;
use SwooleTW\Http\Table\SwooleTable;

trait CanSwooleTable
trait InteractsWithSwooleTable
{
/**
* @var \SwooleTW\Http\Server\Table
Expand Down Expand Up @@ -49,8 +49,9 @@ protected function registerTables()
*/
protected function bindSwooleTable()
{
$this->app->singleton('swoole.table', function () {
$this->app->singleton(SwooleTable::class, function () {
return $this->table;
});
$this->app->alias(SwooleTable::class, 'swoole.table');
}
}
Loading

0 comments on commit 9dff9d1

Please sign in to comment.