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

Commit 357ea5c

Browse files
committed
add support for mac osx
1 parent 6cd39cc commit 357ea5c

File tree

5 files changed

+68
-41
lines changed

5 files changed

+68
-41
lines changed

config/http.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

config/swoole_http.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| HTTP server configurations.
7+
|--------------------------------------------------------------------------
8+
|
9+
| @see https://wiki.swoole.com/wiki/page/274.html
10+
|
11+
*/
12+
'server' => [
13+
'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'),
14+
'port' => env('SWOOLE_HTTP_PORT', '1215'),
15+
'options' => [
16+
'pid_file' => env('SWOOLE_HTTP_PID_FILE', base_path('storage/logs/swoole_http.pid')),
17+
'log_file' => env('SWOOLE_HTTP_LOG_FILE', base_path('storage/logs/swoole_http.log')),
18+
'daemonize' => env('SWOOLE_HTTP_DAEMONIZE', 1),
19+
],
20+
],
21+
];

src/Commands/HttpServerCommand.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ class HttpServerCommand extends Command
3636
*/
3737
protected $pid;
3838

39+
/**
40+
* The configs for this package.
41+
*
42+
* @var array
43+
*/
44+
protected $configs;
45+
46+
/**
47+
* Constructor.
48+
*
49+
* @return void
50+
*/
51+
public function __construct()
52+
{
53+
$this->loadConfigs();
54+
}
55+
3956
/**
4057
* Execute the console command.
4158
*
@@ -47,6 +64,14 @@ public function handle()
4764
$this->runAction();
4865
}
4966

67+
/**
68+
* Load configs.
69+
*/
70+
protected function loadConfigs()
71+
{
72+
$this->configs = $this->laravel['config']->get('swoole_http');
73+
}
74+
5075
/**
5176
* Run action.
5277
*/
@@ -65,10 +90,15 @@ protected function start()
6590
exit(1);
6691
}
6792

93+
$host = $this->configs['server']['host'];
94+
$port = $this->configs['server']['port'];
95+
6896
$this->info('Starting swoole http server...');
69-
$this->info("Swoole http server listend on http://{$this->getHost()}:{$this->getPort()}.");
70-
$this->info('> (You can run this command to ensure the ' .
97+
$this->info("Swoole http server listend on http://{$host}:{$port}.");
98+
if ($this->isDaemon()) {
99+
$this->info('> (You can run this command to ensure the ' .
71100
'swoole_http_server process is running: ps aux|grep "swoole")');
101+
}
72102

73103
$this->laravel->make('swoole.http')->run();
74104
}
@@ -230,7 +260,7 @@ protected function getPid()
230260
*/
231261
protected function getPidPath()
232262
{
233-
return $this->laravel['config']->get('http.server.options.pid_file');
263+
return $this->configs['server']['options']['pid_file'];
234264
}
235265

236266
/**
@@ -244,18 +274,10 @@ protected function removePidFile()
244274
}
245275

246276
/**
247-
* Return server host.
248-
*/
249-
protected function getHost()
250-
{
251-
return $this->laravel['config']->get('http.server.host');
252-
}
253-
254-
/**
255-
* Return server host.
277+
* Return daemonize config.
256278
*/
257-
protected function getPort()
279+
protected function isDaemon()
258280
{
259-
return $this->laravel['config']->get('http.server.port');
281+
return $this->configs['server']['options']['daemonize'];
260282
}
261283
}

src/HttpServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract protected function registerManager();
4141
public function boot()
4242
{
4343
$this->publishes([
44-
__DIR__ . '/../config/http.php' => base_path('config/http.php')
44+
__DIR__ . '/../config/swoole_http.php' => base_path('config/swoole_http.php')
4545
], 'config');
4646
}
4747

@@ -50,7 +50,7 @@ public function boot()
5050
*/
5151
protected function mergeConfig()
5252
{
53-
$this->mergeConfigFrom(__DIR__ . '/../config/http.php', 'http');
53+
$this->mergeConfigFrom(__DIR__ . '/../config/swoole_http.php', 'swoole_http');
5454
}
5555

5656
/**

src/Server/Manager.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class Manager
99
{
10+
const MAC_OSX = 'Darwin';
11+
1012
/**
1113
* @var \Swoole\Http\Server
1214
*/
@@ -94,8 +96,8 @@ protected function initialize()
9496
*/
9597
protected function createSwooleHttpServer()
9698
{
97-
$host = $this->container['config']->get('http.server.host');
98-
$port = $this->container['config']->get('http.server.port');
99+
$host = $this->container['config']->get('swoole_http.server.host');
100+
$port = $this->container['config']->get('swoole_http.server.port');
99101

100102
$this->server = new Server($host, $port);
101103
}
@@ -105,7 +107,7 @@ protected function createSwooleHttpServer()
105107
*/
106108
protected function configureSwooleHttpServer()
107109
{
108-
$config = $this->container['config']->get('http.server.options');
110+
$config = $this->container['config']->get('swoole_http.server.options');
109111

110112
$this->server->set($config);
111113
}
@@ -213,7 +215,7 @@ protected function getApplication()
213215
*/
214216
protected function getPidFile()
215217
{
216-
return $this->container['config']->get('http.server.options.pid_file');
218+
return $this->container['config']->get('swoole_http.server.options.pid_file');
217219
}
218220

219221
/**
@@ -256,6 +258,9 @@ protected function clearCache()
256258
*/
257259
protected function setProcessName($process)
258260
{
261+
if (PHP_OS === static::MAC_OSX) {
262+
return;
263+
}
259264
$serverName = 'swoole_http_server';
260265
$appName = $this->container['config']->get('app.name', 'Laravel');
261266

0 commit comments

Comments
 (0)