Skip to content

Commit

Permalink
change server name, add show_error option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Koryukov committed Oct 23, 2022
1 parent 07dc86c commit b0fa2e3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Laravel Octane dev server starter
# Alternative Laravel Octane swoole server starter

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

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

## Usage

Just start octane server with swoole backend and --watch option,
and see how it reloads after very fatal errors.
and see how it reloads after very fatal errors.
If you want to see error message in http response, set true to OCTANE_SHOW_FATAL_ERROR environment variable.
File renamed without changes.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"filp/whoops": "^2.14"
},
"bin": [
"bin/swoole-server-dev"
"bin/urgent-swoole-server"
]
}
12 changes: 11 additions & 1 deletion src/EmergencyWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EmergencyWorker implements Worker
public function __construct(
protected Client $client,
protected Throwable $exception,
protected array $serverState,
) {
$this->whoops = new Run();
$this->whoops->allowQuit(false);
Expand All @@ -32,11 +33,20 @@ public function handle(Request $request, RequestContext $context): void
$response = new Response();
$response->setStatusCode(500);
$response->headers->add(['Content-Type' => 'text/plain']);
$response->setContent($this->whoops->handleException($this->exception));
if ($this->showError()) {
$response->setContent($this->whoops->handleException($this->exception));
} else {
$response->setContent('Server error.');
}

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

private function showError(): bool
{
return $this->serverState['octaneConfig']['swoole']['show_fatal_error'] ?? false;
}

public function boot(): void
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/OnWorkerStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function bootWorker($server): WorkerContract
]);
} catch (Throwable $e) {
Stream::throwable($e);
return new EmergencyWorker($this->workerState->client, $e);
return new EmergencyWorker($this->workerState->client, $e, $this->serverState);
}
}

Expand Down

0 comments on commit b0fa2e3

Please sign in to comment.