Skip to content

Commit

Permalink
Add Laravel Octane
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrig committed Aug 25, 2021
1 parent d309951 commit 1f32fb3
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


### Added
- [Laravel Octane](https://laravel.com/docs/8.x/octane).

## [0.11.0] - 2021-06-10

### Changed
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"graylog2/gelf-php": "^1.6",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.33",
"laravel/octane": "^1.0",
"laravel/tinker": "^2.0"
},
"require-dev": {
Expand Down
183 changes: 183 additions & 0 deletions src/config/octane.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

use Laravel\Octane\Contracts\OperationTerminated;
use Laravel\Octane\Events\RequestHandled;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Octane\Events\TaskReceived;
use Laravel\Octane\Events\TickReceived;
use Laravel\Octane\Events\WorkerErrorOccurred;
use Laravel\Octane\Events\WorkerStarting;
use Laravel\Octane\Events\WorkerStopping;
use Laravel\Octane\Listeners\CollectGarbage;
use Laravel\Octane\Listeners\DisconnectFromDatabases;
use Laravel\Octane\Listeners\EnsureUploadedFilesAreValid;
use Laravel\Octane\Listeners\FlushTemporaryContainerInstances;
use Laravel\Octane\Listeners\ReportException;
use Laravel\Octane\Listeners\StopWorkerIfNecessary;
use Laravel\Octane\Octane;

return [

/*
|--------------------------------------------------------------------------
| Octane Server
|--------------------------------------------------------------------------
|
| This value determines the default "server" that will be used by Octane
| when starting, restarting, or stopping your server via the CLI. You
| are free to change this to the supported server of your choosing.
|
| Supported: "roadrunner", "swoole"
|
*/

'server' => env('OCTANE_SERVER', 'swoole'),

/*
|--------------------------------------------------------------------------
| Force HTTPS
|--------------------------------------------------------------------------
|
| When this configuration value is set to "true", Octane will inform the
| framework that all absolute links must be generated using the HTTPS
| protocol. Otherwise your links may be generated using plain HTTP.
|
*/

'https' => env('OCTANE_HTTPS', false),

/*
|--------------------------------------------------------------------------
| Octane Listeners
|--------------------------------------------------------------------------
|
| All of the event listeners for Octane's events are defined below. These
| listeners are responsible for resetting your application's state for
| the next request. You may even add your own listeners to the list.
|
*/

'listeners' => [
WorkerStarting::class => [
EnsureUploadedFilesAreValid::class,
],

RequestReceived::class => [
...Octane::prepareApplicationForNextOperation(),
...Octane::prepareApplicationForNextRequest(),
//
],

RequestHandled::class => [
//
],

RequestTerminated::class => [
//
],

TaskReceived::class => [
...Octane::prepareApplicationForNextOperation(),
//
],

TickReceived::class => [
...Octane::prepareApplicationForNextOperation(),
//
],

OperationTerminated::class => [
FlushTemporaryContainerInstances::class,
// DisconnectFromDatabases::class,
// CollectGarbage::class,
],

WorkerErrorOccurred::class => [
ReportException::class,
StopWorkerIfNecessary::class,
],

WorkerStopping::class => [
//
],
],

/*
|--------------------------------------------------------------------------
| Warm / Flush Bindings
|--------------------------------------------------------------------------
|
| The bindings listed below will either be pre-warmed when a worker boots
| or they will be flushed before every new request. Flushing a binding
| will force the container to resolve that binding again when asked.
|
*/

'warm' => [
...Octane::defaultServicesToWarm(),
],

'flush' => [
//
],

/*
|--------------------------------------------------------------------------
| Garbage Collection Threshold
|--------------------------------------------------------------------------
|
| When executing long-lived PHP scripts such as Octane, memory can build
| up before being cleared by PHP. You can force Octane to run garbage
| collection if your application consumes this amount of megabytes.
|
*/

'garbage' => 50,

/*
|--------------------------------------------------------------------------
| Maximum Execution Time
|--------------------------------------------------------------------------
|
| (info) 0 means no maximum limit
|
*/

'max_execution_time' => 30,

/*
|--------------------------------------------------------------------------
| Octane Cache Table
|--------------------------------------------------------------------------
|
| While using Swoole, you may leverage the Octane cache, which is powered
| by a Swoole table. You may set the maximum number of rows as well as
| the number of bytes per row using the configuration options below.
|
*/

'cache' => [
'rows' => 1000,
'bytes' => 10000,
],

/*
|--------------------------------------------------------------------------
| Octane Swoole Tables
|--------------------------------------------------------------------------
|
| While using Swoole, you may define additional tables as required by the
| application. These tables can be used to store data that needs to be
| quickly accessed by other workers on the particular Swoole server.
|
*/

'tables' => [
'example:1000' => [
'name' => 'string:1000',
'votes' => 'int',
],
],

];

0 comments on commit 1f32fb3

Please sign in to comment.