Skip to content

Commit

Permalink
build(core): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana committed Nov 2, 2023
0 parents commit 3797f21
Show file tree
Hide file tree
Showing 21 changed files with 1,323 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Laravel.php Supervisor

on: push

jobs:
cd:
runs-on: ubuntu-latest
steps:
- name: cd
uses: tripteki/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
repotoken: ${{ secrets.REPOSITORY_TOKEN }}
repouser: tripteki
repository: https://packagist.org
language: php
artifact: composer.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Trip Teknologi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<h1 align="center">Supervisor</h1>

This package provides *supervisor-like*, *async-like*, *child-process-like*, etc to build event-listener driven with little painless for your Laravel Project.

Getting Started
---

Installation :

```
$ composer require tripteki/laravelphp-supervisor
```

```
$ npm install pm2 && npm install --save-dev chokidar
```

```
$ pecl install swoole
```

How to use :

- Publish config file into your project's directory with running :

```
php artisan vendor:publish --tag=tripteki-laravelphp-supervisor
```

Usage
---

`php artisan supervisor:<option>`

Option
---

- `start ...` : Start the supervisor.
- foreground *(default)*
- background
- `reload` : Reload the background supervisor.
- `stop` : Stop the background supervisor / `ctrl + c` for foreground supervisor.
- `status` : Show the status of background supervisor.
- `startup` : Generate `ecosystem.json` supervisor startup configuration, do not forget to stop your supervisor process perproject, then see [this](https://pm2.keymetrics.io/docs/usage/startup) to know how to get started.

Snippet
---

```php
/** Use asynchronous? */

__async__(function () {

Model::truncate();
});
```

```php
/** Use asynchronous await-like to get variable? */

[ $model, ] = __async__(fn () => Model::all());
```

```php
/** Use setInterval? */

__setInterval__(function () {

Model::truncate();

}, 2000);
```

```php
/** Use setImmediate? */

__setImmediate__(function () {

Model::truncate();

}, 2000);
```

```php
/** Use exec as replace temporary process? */

$os = __exec__("uname -a");
```

```php
/** Use spawn as one way communication child process? */

/** Stdin stream handler... */
$stdin = fopen("php://temporary", "w+");
fwrite($stdin, "Foo...");
fwrite($stdin, "Bar...");
fwrite($stdin, "Baz...");
fclose($stdin);

/** Stdout handler... */
$stdout = function ($isError, $data)
{
if ($isError) {

// $isError //
}

// $data //
};

__spawn__("python3 example.py", $environment = [], $stdout, $stdin);
```

Author
---

- Trip Teknologi ([@tripteki](https://linkedin.com/company/tripteki))
- Hasby Maulana ([@hsbmaulana](https://linkedin.com/in/hsbmaulana))
59 changes: 59 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "tripteki/laravelphp-supervisor",
"version": "1.0.0",
"description": "Trip Teknologi's Laravel.php Supervisor",

"readme": "README.md",
"license": "MIT",
"authors": [ { "name": "Trip Teknologi", "email": "[email protected]" } ],
"homepage": "https://github.com/tripteki/laravelphp-supervisor",
"support": { "issues": "https://github.com/tripteki/laravelphp-supervisor/issues" },

"require": {

"php": "^8.0.2",
"ext-swoole": "*",

"tripteki/laravelphp-notification": "^1.0.0",
"guzzlehttp/guzzle": "^7.5.0",
"laravel/octane": "^1.3.9",
"beyondcode/laravel-websockets": "^2.0.0-beta.37",
"pusher/pusher-php-server": "^7.2.1"
},

"require-dev": {},

"autoload": {

"files": [

"src/Helpers/Async.php",
"src/Helpers/setImmediate.php",
"src/Helpers/setInterval.php",
"src/Helpers/Exec.php",
"src/Helpers/Spawn.php"
],

"psr-4": {

"Tripteki\\Supervisor\\": "src/"
}
},

"autoload-dev": {},

"extra": {

"laravel": {

"dont-discover": [],

"providers": [

"Tripteki\\Supervisor\\Providers\\SupervisorServiceProvider"
],

"aliases": []
}
}
}
157 changes: 157 additions & 0 deletions config/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

use Laravel\Octane\Octane;
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\TaskTerminated;
use Laravel\Octane\Events\TickReceived;
use Laravel\Octane\Events\TickTerminated;
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\EnsureUploadedFilesCanBeMoved;
use Laravel\Octane\Listeners\FlushTemporaryContainerInstances;
use Laravel\Octane\Listeners\FlushUploadedFiles;
use Laravel\Octane\Listeners\ReportException;
use Laravel\Octane\Listeners\StopWorkerIfNecessary;

return [

"host" => env("SERVER_HOST", "127.0.0.1"),
"port" => env("SERVER_PORT", "8000"),
"https" => env("SERVER_HTTPS", false),

"state_file" => storage_path("logs/server-state.json"),

"swoole" => [

"options" => [

"pid_file" => storage_path("logs/server/server.pid"),
"log_file" => storage_path("logs/server.log"),

// "ssl_key_file" => ".key", //
// "ssl_cert_file" => ".cert", //
],

"ssl" => env("SERVER_HTTPS", false),
],



"cache" => [

"rows" => 1000,
"bytes" => 10000,
],

"tables" => [

//
],

"watch" => [

"bin",
"src",
"app",
"bootstrap",
"config",
"database",
"public/**/*.php",
"resources/**/*.php",
"routes",
"composer.lock",
".env",
],



"listeners" => [

WorkerStarting::class => [

EnsureUploadedFilesAreValid::class,
EnsureUploadedFilesCanBeMoved::class,
],

RequestReceived::class => [

...Octane::prepareApplicationForNextOperation(),
...Octane::prepareApplicationForNextRequest(),
],

RequestHandled::class => [

//
],

RequestTerminated::class => [

// FlushUploadedFiles::class, //
],

TaskReceived::class => [

...Octane::prepareApplicationForNextOperation(),
],

TaskTerminated::class => [

//
],

TickReceived::class => [

...Octane::prepareApplicationForNextOperation(),
],

TickTerminated::class => [

//
],

OperationTerminated::class => [

FlushTemporaryContainerInstances::class,
// DisconnectFromDatabases::class, //
// CollectGarbage::class, //
],

WorkerErrorOccurred::class => [

ReportException::class,
StopWorkerIfNecessary::class,
],

WorkerStopping::class => [

//
],
],



"warm" => [

...Octane::defaultServicesToWarm(),
],

"flush" => [

//
],



"garbage" => 50,
"max_execution_time" => 30,
"server" => "swoole",

];
Loading

0 comments on commit 3797f21

Please sign in to comment.