diff --git a/src/Configuration/Plugins.php b/src/Configuration/Plugins.php index 82fead3..3b5382a 100644 --- a/src/Configuration/Plugins.php +++ b/src/Configuration/Plugins.php @@ -4,12 +4,34 @@ namespace Spiral\RoadRunner\Console\Configuration; +use Spiral\RoadRunner\Console\Configuration\Section\Http; +use Spiral\RoadRunner\Console\Configuration\Section\Jobs; +use Spiral\RoadRunner\Console\Configuration\Section\Kv; +use Spiral\RoadRunner\Console\Configuration\Section\Metrics; +use Spiral\RoadRunner\Console\Configuration\Section\Rpc; use Spiral\RoadRunner\Console\Configuration\Section\SectionInterface; +use Spiral\RoadRunner\Console\Configuration\Section\Server; +use Spiral\RoadRunner\Console\Configuration\Section\Version; use Spiral\Tokenizer\ClassLocator; use Symfony\Component\Finder\Finder; final class Plugins { + /** + * @psalm-var array + * + * Default plugins in a class-string format. + */ + private array $defaultPlugins = [ + Version::class, + Rpc::class, + Server::class, + Http::class, + Jobs::class, + Kv::class, + Metrics::class, + ]; + /** * @var string[] * @@ -51,7 +73,7 @@ public static function fromPreset(string $preset): self public function getPlugins(): array { if ($this->requestedPlugins === []) { - return $this->available; + return $this->defaultPlugins; } $plugins = []; diff --git a/src/Configuration/Section/Http.php b/src/Configuration/Section/Http.php index e7f497c..46c60de 100644 --- a/src/Configuration/Section/Http.php +++ b/src/Configuration/Section/Http.php @@ -12,121 +12,20 @@ public function render(): array { return [ self::NAME => [ - 'address' => '127.0.0.1:8080', - 'internal_error_code' => 505, - 'access_logs' => false, - 'max_request_size' => 256, + 'address' => '0.0.0.0:8080', 'middleware' => [ - 'headers', - 'gzip' - ], - 'trusted_subnets' => [ - '10.0.0.0/8', - '127.0.0.0/8', - '172.16.0.0/12', - '192.168.0.0/16', - '::1/128', - 'fc00::/7', - 'fe80::/10' - ], - 'new_relic' => [ - 'app_name' => 'app', - 'license_key' => 'key' - ], - 'cache' => [ - 'driver' => 'memory', - 'cache_methods' => [ - 'GET', - 'HEAD', - 'POST' - ], - 'config' => [] - ], - 'uploads' => [ - 'dir' => '/tmp', - 'forbid' => [ - '.php', - '.exe', - '.bat', - '.sh' - ], - 'allow' => [ - '.html', - '.aaa' - ] - ], - 'headers' => [ - 'cors' => [ - 'allowed_origin' => '*', - 'allowed_headers' => '*', - 'allowed_methods' => 'GET,POST,PUT,DELETE', - 'allow_credentials' => true, - 'exposed_headers' => 'Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma', - 'max_age' => 600 - ], - 'request' => [ - 'input' => 'custom-header', - ], - 'response' => [ - 'X-Powered-By' => 'RoadRunner' - ] + 'gzip', + 'static' ], 'static' => [ - 'dir' => '.', - 'forbid' => [''], - 'calculate_etag' => false, - 'weak' => false, - 'allow' => [ - '.txt', - '.php' - ], - 'request' => [ - 'input' => 'custom-header' - ], - 'response' => [ - 'output' => 'output-header' - ] + 'dir' => 'public', + 'forbid' => ['.php', '.htaccess'], ], 'pool' => [ - 'debug' => false, - 'command' => 'php my-super-app.php', - 'num_workers' => 0, - 'max_jobs' => 64, - 'allocate_timeout' => '60s', - 'destroy_timeout' => '60s', + 'num_workers' => 1, 'supervisor' => [ - 'watch_tick' => '1s', - 'ttl' => '0s', - 'idle_ttl' => '10s', - 'max_worker_memory' => 128, - 'exec_ttl' => '60s' + 'max_worker_memory' => 100 ] - ], - 'ssl' => [ - 'address' => '127.0.0.1:443', - 'acme' => [ - 'certs_dir' => 'rr_le_certs', - 'email' => 'you-email-here@email', - 'alt_http_port' => 80, - 'alt_tlsalpn_port' => 443, - 'challenge_type' => 'http-01', - 'use_production_endpoint' => true, - 'domains' => [ - 'your-cool-domain.here', - 'your-second-domain.here' - ] - ], - 'redirect' => true, - 'cert' => '/ssl/server.crt', - 'key' => '/ssl/server.key', - 'root_ca' => '/ssl/root.crt' - ], - 'fcgi' => [ - 'address' => 'tcp://0.0.0.0:7921' - ], - 'http2' => [ - 'h2c' => false, - 'max_concurrent_streams' => 128 ] ] ]; diff --git a/src/Configuration/Section/Jobs.php b/src/Configuration/Section/Jobs.php index dea7053..4825a56 100644 --- a/src/Configuration/Section/Jobs.php +++ b/src/Configuration/Section/Jobs.php @@ -12,98 +12,11 @@ public function render(): array { return [ self::NAME => [ - 'num_pollers' => 32, - 'pipeline_size' => 100000, 'pool' => [ - 'command' => '', - 'num_workers' => 10, - 'max_jobs' => 0, - 'allocate_timeout' => '60s', - 'destroy_timeout' => '60s' + 'num_workers' => 2, + 'max_worker_memory' => 100 ], - 'pipelines' => [ - 'test-local' => [ - 'driver' => 'memory', - 'config' => [ - 'priority' => 10, - 'prefetch' => 10000 - ] - ], - 'test-local-1' => [ - 'driver' => 'boltdb', - 'config' => [ - 'file' => 'path/to/rr.db', - 'priority' => 10, - 'prefetch' => 10000 - ] - ], - 'test-local-2' => [ - 'driver' => 'amqp', - 'config' => [ - 'prefetch' => 10, - 'priority' => 1, - 'durable' => false, - 'delete_queue_on_stop' => false, - 'queue' => 'test-1-queue', - 'exchange' => 'default', - 'exchange_type' => 'direct', - 'routing_key' => 'test', - 'exclusive' => false, - 'multiple_ack' => false, - 'requeue_on_fail' => false - ] - ], - 'test-local-3' => [ - 'driver' => 'beanstalk', - 'config' => [ - 'priority' => 11, - 'tube_priority' => 1, - 'tube' => 'default-1', - 'reserve_timeout' => '10s' - ] - ], - 'test-local-4' => [ - 'driver' => 'sqs', - 'config' => [ - 'priority' => 10, - 'prefetch' => 10, - 'visibility_timeout' => 0, - 'wait_time_seconds' => 0, - 'queue' => 'default', - 'attributes' => [ - 'DelaySeconds' => 0, - 'MaximumMessageSize' => 262144, - 'MessageRetentionPeriod' => 345600, - 'ReceiveMessageWaitTimeSeconds' => 0, - 'VisibilityTimeout' => 30 - ], - 'tags' => [ - 'test' => 'tag' - ] - ] - ], - 'test-local-5' => [ - 'driver' => 'nats', - 'config' => [ - 'priority' => 2, - 'prefetch' => 100, - 'subject' => 'default', - 'stream' => 'foo', - 'deliver_new' => true, - 'rate_limit' => 100, - 'delete_stream_on_stop' => false, - 'delete_after_ack' => false - ] - ] - ], - 'consume' => [ - 'test-local', - 'test-local-1', - 'test-local-2', - 'test-local-3', - 'test-local-4', - 'test-local-5' - ] + 'consume' => [] ] ]; } diff --git a/src/Configuration/Section/Kv.php b/src/Configuration/Section/Kv.php index fda4807..aac3b5b 100644 --- a/src/Configuration/Section/Kv.php +++ b/src/Configuration/Section/Kv.php @@ -12,54 +12,18 @@ public function render(): array { return [ self::NAME => [ - 'boltdb-south' => [ - 'driver' => 'boltdb', - 'config' => [ - 'file' => 'rr.db', - 'permissions' => 0777, - 'interval' => 40 - ] - ], - 'us-central-kv' => [ - 'driver' => 'memcached', + 'local' => [ + 'driver' => 'memory', 'config' => [ - 'addr' => [ - 'localhost:11211' - ] + 'interval' => 60 ] ], - 'fast-kv-fr' => [ + 'redis' => [ 'driver' => 'redis', 'config' => [ 'addrs' => [ 'localhost:6379' - ], - 'master_name' => '', - 'username' => '', - 'password' => '', - 'db' => 0, - 'sentinel_password' => '', - 'route_by_latency' => false, - 'route_randomly' => false, - 'dial_timeout' => 0, - 'max_retries' => 1, - 'min_retry_backoff' => 0, - 'max_retry_backoff' => 0, - 'pool_size' => 0, - 'min_idle_conns' => 0, - 'max_conn_age' => 0, - 'read_timeout' => 0, - 'write_timeout' => 0, - 'pool_timeout' => 0, - 'idle_timeout' => 0, - 'idle_check_freq' => 0, - 'read_only' => false - ] - ], - 'local-memory' => [ - 'driver' => 'memory', - 'config' => [ - 'interval' => 1 + ] ] ] ] diff --git a/src/Configuration/Section/Metrics.php b/src/Configuration/Section/Metrics.php index de55121..1564893 100644 --- a/src/Configuration/Section/Metrics.php +++ b/src/Configuration/Section/Metrics.php @@ -12,30 +12,7 @@ public function render(): array { return [ self::NAME => [ - 'address' => '127.0.0.1:2112', - 'collect' => [ - 'app_metric' => [ - 'type' => 'histogram', - 'help' => 'Custom application metric', - 'labels' => [ - 'type' - ], - 'buckets' => [ - 0.1, - 0.2, - 0.3, - 1.0 - ], - 'objectives' => [ - [ - '1.4' => 2.3 - ], - [ - '2.0' => 1.4 - ] - ] - ] - ] + 'address' => 'localhost:2112' ] ]; } diff --git a/src/Configuration/Section/Server.php b/src/Configuration/Section/Server.php index 29fa37b..20afe72 100644 --- a/src/Configuration/Section/Server.php +++ b/src/Configuration/Section/Server.php @@ -12,15 +12,8 @@ public function render(): array { return [ self::NAME => [ - 'on_init' => [ - 'command' => 'any php or script here', - 'exec_timeout' => '20s', - ], - 'command' => 'php psr-worker.php', - 'user' => '', - 'group' => '', - 'relay' => 'pipes', - 'relay_timeout' => '60s' + 'command' => 'php app.php', + 'relay' => 'pipes' ] ]; } diff --git a/src/DownloadProtocBinaryCommand.php b/src/DownloadProtocBinaryCommand.php index 6c89569..4179565 100644 --- a/src/DownloadProtocBinaryCommand.php +++ b/src/DownloadProtocBinaryCommand.php @@ -167,8 +167,9 @@ private function findAsset( foreach ($filtered as $release) { $asset = $release->getAssets() - ->filter(static fn (AssetInterface $asset): bool => - 0 === \strncmp($asset->getName(), 'protoc-gen-php-grpc', \strlen('protoc-gen-php-grpc')) + ->filter( + static fn (AssetInterface $asset): bool => + \str_starts_with($asset->getName(), 'protoc-gen-php-grpc') ) ->whereArchitecture($archOption) ->whereOperatingSystem($osOption)