2017 © Pedro Peláez
 

library emit-php

A PHP framework to develop WebSocket, HTTP and FCGI Applications

image

rnaga/emit-php

A PHP framework to develop WebSocket, HTTP and FCGI Applications

  • Thursday, March 23, 2017
  • by rnaga
  • Repository
  • 2 Watchers
  • 8 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EmitPHP

EmitPHP is a PHP framework that works with non-blocking I/O., (*1)

You can write your web applications and APIs in HTTP, FCGI and WebSocket., (*2)

As of now, this is an experimental project and there still exists errors and bugs., (*3)

Installation

  • It requires PHP 7(CLI) and composer to run
  • If you haven't installed composer, run below to install it.
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer install

Now you can run Examples, (*4)

Usage

WebSocket

Yes, EmitPHP supports WebSocket., (*5)

you can create your WebSocket Application with a few lines of code., (*6)

Below is an example of how to create a WebSocket Application., (*7)

// Create a new WS Application
$app = (new WSServer())->listen(4000)->app();
// Triggers when messages received
$app->on('message', function($conn, $msg){
    // Echo message
    $conn->send("echo => ". $msg);
    // Close the connection
    $conn->close();
});

\Emit\Loop();

HTTP

You can easily create a HTTP server as below, (*8)

$server = (new HTTPServer())->listen(4000);
$server->on('request', function($req, $res){
    // Send response
    $res->send("Hello World");
    // Close connection
    $res->end();
});

\Emit\Loop();

Router

Example for using Router, (*9)

$server = (new HTTPServer())->listen(9000);
// Create a new Route
$route = $server->route();
// Get method 
$route->get("/", function($req, $res, $next){
    $res->send("Hello World");
    // Calling the next handler
    $next();
});
// Register the route
$server->use($route);

\Emit\Loop();

FCGI

EmitPHP supports FCGI which works with Web Servers such as apache, (*10)

$server = (new FCGIServer())->listen(9000);
$server->on('request', function($req, $res){
    // Send response
    $res->send("Hello World");
    // Close connection
    $res->end();
});

\Emit\Loop();

See examples for more details., (*11)

What's next

Please send me your feeback at emitphp@gmail.com and let me know how you like it. If there are demands, I will work more., (*12)

And if any of you wants to join the project, please let me know., (*13)

License

EmitPHP is licensed under the MIT license. See License File for more information., (*14)

The Versions

23/03 2017

dev-master

9999999-dev

A PHP framework to develop WebSocket, HTTP and FCGI Applications

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Ryohei Nagatsuka

http websocket eventemitter fcgi