Skip to content

Commit b0fa2e3

Browse files
author
Ivan Koryukov
committed
change server name, add show_error option
1 parent 07dc86c commit b0fa2e3

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Laravel Octane dev server starter
1+
# Alternative Laravel Octane swoole server starter
22

3-
With this package your swoole dev server continue work even if you change code with syntax error.
3+
With this package your swoole server continue work even if you change code with syntax error.
44
Original server stops in this case.
55

66
## Installation
@@ -12,11 +12,13 @@ composer install ensi/laravel-octane-starter
1212
and add this section to **config/octane.php** file
1313
```
1414
'swoole' => [
15-
'command' => '/var/www/vendor/bin/swoole-server-dev'
15+
'command' => '/var/www/vendor/bin/urgent-swoole-server',
16+
'show_fatal_error' => env('OCTANE_SHOW_FATAL_ERROR', false),
1617
]
1718
```
1819

1920
## Usage
2021

2122
Just start octane server with swoole backend and --watch option,
22-
and see how it reloads after very fatal errors.
23+
and see how it reloads after very fatal errors.
24+
If you want to see error message in http response, set true to OCTANE_SHOW_FATAL_ERROR environment variable.
File renamed without changes.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"filp/whoops": "^2.14"
1414
},
1515
"bin": [
16-
"bin/swoole-server-dev"
16+
"bin/urgent-swoole-server"
1717
]
1818
}

src/EmergencyWorker.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class EmergencyWorker implements Worker
2020
public function __construct(
2121
protected Client $client,
2222
protected Throwable $exception,
23+
protected array $serverState,
2324
) {
2425
$this->whoops = new Run();
2526
$this->whoops->allowQuit(false);
@@ -32,11 +33,20 @@ public function handle(Request $request, RequestContext $context): void
3233
$response = new Response();
3334
$response->setStatusCode(500);
3435
$response->headers->add(['Content-Type' => 'text/plain']);
35-
$response->setContent($this->whoops->handleException($this->exception));
36+
if ($this->showError()) {
37+
$response->setContent($this->whoops->handleException($this->exception));
38+
} else {
39+
$response->setContent('Server error.');
40+
}
3641

3742
$this->client->respond($context, new OctaneResponse($response));
3843
}
3944

45+
private function showError(): bool
46+
{
47+
return $this->serverState['octaneConfig']['swoole']['show_fatal_error'] ?? false;
48+
}
49+
4050
public function boot(): void
4151
{
4252
}

src/OnWorkerStart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function bootWorker($server): WorkerContract
2828
]);
2929
} catch (Throwable $e) {
3030
Stream::throwable($e);
31-
return new EmergencyWorker($this->workerState->client, $e);
31+
return new EmergencyWorker($this->workerState->client, $e, $this->serverState);
3232
}
3333
}
3434

0 commit comments

Comments
 (0)