Skip to content

Commit

Permalink
Merge pull request #2 from msmakouz/updating-sf
Browse files Browse the repository at this point in the history
Updating SF, adding RR and Cycle bridges
  • Loading branch information
butschster authored Jul 14, 2022
2 parents 73af61e + dc72d30 commit 3cb0a8a
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 90 deletions.
6 changes: 3 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Debug mode disabled view cache and enabled higher verbosity.
DEBUG = true
DEBUG=true

# Set to application specific value, used to encrypt/decrypt cookies and etc.
ENCRYPTER_KEY = {encrypt-key}
ENCRYPTER_KEY={encrypt-key}

# Set to TRUE to disable confirmation in `migrate` commands.
SAFE_MIGRATIONS = true
SAFE_MIGRATIONS=true
46 changes: 25 additions & 21 deletions .rr.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# grpc service configuration.
grpc:
listen: tcp://0.0.0.0:50051
proto: "proto/service.proto"
workers.command: "php app.php"
tls.key: "app.key"
tls.cert: "app.crt"
version: '2.7'

# queue and jobs
jobs:
dispatch:
app-job-*.pipeline: "local"
pipelines:
local:
broker: "ephemeral"
consume: ["local"]
rpc:
listen: tcp://127.0.0.1:6001

workers:
server:
command: "php app.php"
pool.numWorkers: 2
relay: pipes

# control the max memory usage
limit:
services:
grpc.maxMemory: 100
# queue and jobs
jobs:
consume: [ "local" ]
pool:
num_workers: 2
supervisor:
max_worker_memory: 100

# grpc service configuration.
grpc:
listen: "tcp://0.0.0.0:50051"
proto:
- "proto/service.proto"
tls:
key: "app.key"
cert: "app.crt"
pool:
num_workers: 2
supervisor:
max_worker_memory: 100
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of
Server Requirements
--------
Make sure that your server is configured with following PHP version and extensions:
* PHP 7.2+, 64bit
* PHP 8.0+, 64bit
* **mb-string** extension
* PDO Extension with desired database drivers
* [Install](https://github.com/protocolbuffers/protobuf/tree/master/php) `protobuf-ext` to gain higher performance.
Expand Down Expand Up @@ -48,11 +48,16 @@ In order to run GRPC server you must specify location of server key and certific

```yaml
grpc:
listen: tcp://0.0.0.0:50051
proto: "proto/service.proto"
workers.command: "php app.php"
tls.key: "app.key"
tls.cert: "app.crt"
listen: "tcp://0.0.0.0:50051"
proto:
- "proto/service.proto"
tls:
key: "app.key"
cert: "app.crt"
pool:
num_workers: 2
supervisor:
max_worker_memory: 100
```
To issue local certificate:
Expand All @@ -64,13 +69,13 @@ $ openssl req -newkey rsa:2048 -nodes -keyout app.key -x509 -days 365 -out app.c
To start application server execute:

```
$ ./spiral serve -v -d
$ ./rr serve
```

On Windows:

```
$ spiral.exe serve -v -d
$ rr.exe serve
```

You can test your endpoints using any GRPC client. For example using [grpcui](https://github.com/fullstorydev/grpcui):
Expand All @@ -90,7 +95,7 @@ In order to compile protobuf declarations into service code make sure to install
To update or generate service code for your application run:

```
$ php ./app.php grpc:generate proto/service.proto
$ php ./app.php grpc:generate
```

Generated code will be available in `app/src/Service`. Implemented service will be automatically registered in your application.
Expand Down
12 changes: 8 additions & 4 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
//
// Initialize shared container, bindings, directories and etc.
//
$app = App::init(['root' => __DIR__]);
$app = App::create(
directories: ['root' => __DIR__]
)->run();

if ($app !== null) {
$code = (int)$app->serve();
exit($code);
if ($app === null) {
exit(255);
}

$code = (int)$app->serve();
exit($code);
11 changes: 6 additions & 5 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

declare(strict_types=1);

use Cycle\Database\Config;

return [
/**
* Default database connection
Expand Down Expand Up @@ -36,10 +38,9 @@
* the driver class and its connection options.
*/
'drivers' => [
'sqlite' => [
'driver' => \Spiral\Database\Driver\SQLite\SQLiteDriver::class,
'connection' => 'sqlite:' . directory('root') . 'app.db',
'profiling' => true,
],
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\MemoryConnectionConfig(),
queryCache: true
),
],
];
13 changes: 13 additions & 0 deletions app/config/grpc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

return [
/**
* Path to protoc-gen-php-grpc library.
*/
'binaryPath' => __DIR__ . '/../../protoc-gen-php-grpc',
'services' => [
__DIR__ . '/../../proto/service.proto',
],
];
19 changes: 12 additions & 7 deletions app/src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

use Spiral\Bootloader as Framework;
use Spiral\DotEnv\Bootloader as DotEnv;
use Spiral\Cycle\Bootloader as CycleBridge;
use Spiral\Framework\Kernel;
use Spiral\Prototype\Bootloader as Prototype;
use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge;

class App extends Kernel
{
Expand All @@ -31,20 +33,23 @@ class App extends Kernel
Framework\Security\EncrypterBootloader::class,

// Databases
Framework\Database\DatabaseBootloader::class,
Framework\Database\MigrationsBootloader::class,
CycleBridge\DatabaseBootloader::class,
CycleBridge\MigrationsBootloader::class,

// ORM
Framework\Cycle\CycleBootloader::class,
Framework\Cycle\ProxiesBootloader::class,
Framework\Cycle\AnnotatedBootloader::class,
CycleBridge\SchemaBootloader::class,
CycleBridge\CycleOrmBootloader::class,
CycleBridge\AnnotatedBootloader::class,
CycleBridge\CommandBootloader::class,

// Dispatchers
Framework\GRPC\GRPCBootloader::class,
Framework\Jobs\JobsBootloader::class,
RoadRunnerBridge\GRPCBootloader::class,
RoadRunnerBridge\QueueBootloader::class,

// Framework commands
Framework\CommandBootloader::class,
CycleBridge\CommandBootloader::class,
RoadRunnerBridge\CommandBootloader::class,

// Debugging
Framework\DebugBootloader::class,
Expand Down
Loading

0 comments on commit 3cb0a8a

Please sign in to comment.