Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igniphp/network
Network utilities: swoole based http server, psr-7 and psr-15 implementations
https://github.com/igniphp/network
framework php7 psr-15 psr-7 server swoole
Last synced: 3 days ago
JSON representation
Network utilities: swoole based http server, psr-7 and psr-15 implementations
- Host: GitHub
- URL: https://github.com/igniphp/network
- Owner: igniphp
- Created: 2018-08-15T06:38:02.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-18T07:23:12.000Z (almost 5 years ago)
- Last Synced: 2024-09-05T16:38:23.678Z (2 months ago)
- Topics: framework, php7, psr-15, psr-7, server, swoole
- Language: PHP
- Homepage:
- Size: 105 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ![Igni logo](https://github.com/igniphp/common/blob/master/logo/full.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
[![Build Status](https://travis-ci.org/igniphp/network.svg?branch=master)](https://travis-ci.org/igniphp/network)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/igniphp/network/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/igniphp/network/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/igniphp/network/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/igniphp/network/?branch=master)## Requirements
- PHP 7.1 or better
- Swoole extension is required for network server to work## Installation
Linux users:
```
pecl install swoole
composer install igniphp/network
```Mac users with homebrew:
```
brew install swoole
composer install igniphp/network
```
or:
```
brew install homebrew/php/php71-swoole
composer install igniphp/network
```## Basic Usage
```php
start();
```### Listeners
Igni http server uses event-driven model that makes it easy to scale and extend.
There are five type of events available, each of them extends `Igni\Network\Server\Listener` interface:
- `Igni\Network\Server\OnStartListener` fired when server starts
- `Igni\Network\Server\OnStopListener` fired when server stops
- `Igni\Network\Server\OnConnectListener` fired when new client connects to the server
- `Igni\Network\Server\OnCloseListener` fired when connection with the client is closed
- `Igni\Network\Server\OnRequestListener` fired when new request is dispatched
```php
addListener(new class implements OnRequestListener {
public function onRequest(Client $client, ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
return $response->withBody(Stream::fromString("Hello world"));
}
});
$server->start();
```### Configuration
Server can be easily configured with `Igni\Network\Server\Configuration` class.
Please consider following example:
```php
start();
```##### Enabling ssl support
```php
enableSsl($certFile, $keyFile);// Create server instance.
$server = new \Igni\Network\Server($configuration);
$server->start();
```##### Running server as a daemon
```php
enableDaemon($pidFile);// Create server instance.
$server = new \Igni\Network\Server($configuration);
$server->start();
```
More examples can be found in the `./examples/` directory.