Skip to main content

Symfony intergation

This bundle provides integration of PHPStreamServer with the Symfony framework.

Installation

$ composer require phpstreamserver/symfony

Configuration

Enable the bundle

config/bundles.php
<?php

return [
// ...
PHPStreamServer\Symfony\PHPStreamServerBundle::class => ['all' => true],
];

Create phpss.config.php file in the config directory

config/phpss.config.php
<?php

use PHPStreamServer\Core\ReloadStrategy\ExceptionReloadStrategy;
use PHPStreamServer\Core\Server;
use PHPStreamServer\Symfony\Worker\SymfonyHttpServerProcess;

return static function (Server $server): void {
$server->addWorker(new SymfonyHttpServerProcess(
listen: '0.0.0.0:80',
count: 1,
reloadStrategies: [
new ExceptionReloadStrategy(),
],
));
};

You can register additional plugins and workers in this file.
This bundle adds new Symfony-specific workers:

Create phpss file in the bin directory

bin/phpss
#!/usr/bin/env php
<?php

use App\Kernel;
use PHPStreamServer\Symfony\PHPStreamServerRuntime;

$_SERVER['APP_RUNTIME'] = PHPStreamServerRuntime::class;

require_once \dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

Start the server

$ bin/phpss start

This bundle adds new Symfony-specific options to the start command: --env, --no-debug. For more details, refer to the help output.

Intergation with Monolog

If you use Monolog as your main logging system in Symfony, you can route all logs to the PHPStreamServer logger. This bundle provides a special Monolog handler for seamless integration, which can be configured in the monolog.yaml file.

config/packages/monolog.yaml
when@dev:
monolog:
handlers:
main:
type: service
id: phpss.monolog_handler
channels: ["!event", "!doctrine"]
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]

when@prod:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: service
id: phpss.monolog_handler
channels: ["!event", "!doctrine"]
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]