keboola / gelf-server
Simple PHP server for GELF logger
Installs: 22 788
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 17
Forks: 0
pkg:composer/keboola/gelf-server
Requires
- php: ^8.1
- ext-json: *
- ext-zlib: *
- graylog2/gelf-php: ^2.0
- react/datagram: ^1.9
- react/socket: ^1.12
- symfony/process: ^5.4|^6.0
Requires (Dev)
- ext-sockets: *
- keboola/coding-standard: >=14.0
- phpstan/phpstan: ^1.9
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^9.5
- sempro/phpunit-pretty-print: ^1.4
- symfony/dotenv: ^5.4|^6.0
README
A php implementation of a gelf compatible backend like Graylog2. This library provides a simple server to which a GELF client can connect.
Installation
Recommended installation via composer:
Add gelf-server to composer.json either by running composer require keboola/gelf-server or by defining it manually:
"require": {
// ...
"keboola/gelf-server": "^1.1"
// ...
}
Reinstall dependencies: composer install
Usage
To create a server, use the ServerFactory class:
$server = ServerFactory::createServer(ServerFactory::SERVER_TCP);
To start listening for connections, us the start method. This method has the following parameters:
$minPortand$maxPort- to set port on which the server listens. To listen on a single port use the same value for both$minPortand$maxPort. Otherwise the server will randomly choose a free port in the specified range (inclusive).$onStart- Callback executed when the server successfully started listening, the callback signature isfunction ($port), which gives you the actual port the server is listening on.$onProcess- Callback executed periodically when the server is running. The callback has signaturefunction (&$terminated). The server will keep running indefinitely until you set$terminatedto true in this callback.$onEvent- Callback executed when a GELF event is received. The callback has signaturefunction ($event). The$eventvariable contains associative array with GELF fields$onTerminate- Optional callback executed when the server terminates - after it stops listening for connections. The callback signature isfunction ().
Examples
For usage examples, see the /examples directory.
License
MIT licensed, see LICENSE file.