All Projects → pachico → Slim Swoole

pachico / Slim Swoole

Licence: mit
Convenient library to run SlimPHP applications with Swoole

Projects that are alternatives of or similar to Slim Swoole

slim-swoole
Slim 3 MVC Skeleton With Swoole
Stars: ✭ 52 (-30.67%)
Mutual labels:  slim, swoole
Swoft Framework
[READ ONLY] Swoft Framework, base of Swoft
Stars: ✭ 70 (-6.67%)
Mutual labels:  swoole
Framework
The Lawoole framework
Stars: ✭ 33 (-56%)
Mutual labels:  swoole
Bottyclient
A slim Discord client with many cool features including less network traffic which supports bot tokens, but user tokens theoretically work too. Tags: Discord Bot Client Token for Bot Botting Download English
Stars: ✭ 58 (-22.67%)
Mutual labels:  slim
Authorize Slim 4
Slim 4 Authorization Tutorial
Stars: ✭ 39 (-48%)
Mutual labels:  slim
Slimvalidation
A validator for PHP with Respect/Validation
Stars: ✭ 62 (-17.33%)
Mutual labels:  slim
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+1054.67%)
Mutual labels:  swoole
Mqtt
🕹 MQTT Protocol Analysis and Coroutine Client for PHP. Support for 3.1, 3.1.1 and 5.0 versions of the MQTT protocol.
Stars: ✭ 72 (-4%)
Mutual labels:  swoole
Phpspidermagnetbittorrent
php实现p2p中DHT网络爬虫,并提供搜索下载
Stars: ✭ 64 (-14.67%)
Mutual labels:  swoole
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (+1308%)
Mutual labels:  swoole
Elliot
Comprehensive and Rigorous Framework for Reproducible Recommender Systems Evaluation
Stars: ✭ 49 (-34.67%)
Mutual labels:  slim
Swoole Performance Tests
Performance tests of swoole against other PHP application server setups
Stars: ✭ 40 (-46.67%)
Mutual labels:  swoole
Mqcms
🤖 ⚡️ 麻雀虽小 五脏俱全 基于hyperf的快速优雅的应用开发框架
Stars: ✭ 64 (-14.67%)
Mutual labels:  swoole
Socket Io
基于Hyperf微服务协程框架开发的sokcet-io分布式系统
Stars: ✭ 38 (-49.33%)
Mutual labels:  swoole
Slim3
Slim Framework 3 Skeleton Application
Stars: ✭ 70 (-6.67%)
Mutual labels:  slim
Lean
Use the PHP League's Container package with auto-wiring support as the core container in Slim 3
Stars: ✭ 30 (-60%)
Mutual labels:  slim
Gomoku
this is a Gomoku game's client and server, which bulid by canvas and swoole
Stars: ✭ 44 (-41.33%)
Mutual labels:  swoole
Swoole Ide Helper
Auto completion, trigger suggest and view docs for Swoole in editor.
Stars: ✭ 1,116 (+1388%)
Mutual labels:  swoole
Php Coroutine Engine
This project for php-fpm support coroutine
Stars: ✭ 74 (-1.33%)
Mutual labels:  swoole
Mobilenet V2
Repository for "Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation".
Stars: ✭ 73 (-2.67%)
Mutual labels:  slim

slim-swoole

Scrutinizer Code Quality Code Coverage Build Status Software License

This is a brige library to run Slim framework Slim framework applications using Swoole engine.

Overview

The main purpose of this library is to easily run your already existing SlimPHP applications using Swoole Framework. It requires you to bootstrap your application only once when you start Swoole HTTP server and, thanks to its event driven design, it will process each request reusing your already started application for better performance.

The execution sequence is as follows:

  1. You bootstrap your SlimPHP application as you would normally do.
  2. You instantiate the BrigeManager passing to it your SlimPHP application.
  3. You start Swoole's HTTP server.
  4. You bind to the on('request') event handler the BridgeManager instance which will:
    1. Transform the Swoole request to a SlimPHP based on server and request attributes.
    2. Process your request through SlimPHP's application stack (including middlewares)
    3. Merge SlimPHP Response to Swoole Response
    4. End the request. All this is done under the hood, so you will just need to call:
$bridgeManager->process($swooleRequest, $swooleResponse)->end();

(See usage paragraph for a complete example.)

Caution: it is still in development so any contribution and test will be more than welcome.

Requirements

  • PHP-CLI >= 7.0 (Required by Swoole)
  • Swoole framework (this has been tested with version 1.10.1)

Install

Via Composer

$ composer require pachico/slim-swoole

Usage

<?php

use Pachico\SlimSwoole\BridgeManager;
use Slim\Http;

require __DIR__ . '/../vendor/autoload.php';

/**
 * This is how you would normally bootstrap your Slim application
 * For the sake of demonstration, we also add a simple middleware
 * to check that the entire app stack is being setup and executed
 * properly.
 */
$app = new \Slim\App();
$app->any('/foo[/{myArg}]', function (Http\Request $request, Http\Response $response, array $args) {
    $data = [
        'args' => $args,
        'body' => (string) $request->getBody(),
        'parsedBody' => $request->getParsedBody(),
        'params' => $request->getParams(),
        'headers' => $request->getHeaders(),
        'uploadedFiles' => $request->getUploadedFiles()
    ];

    return $response->withJson($data);
})->add(function (Http\Request $request, Http\Response $response, callable $next) {

    $response->getBody()->write('BEFORE' . PHP_EOL);
    $response = $next($request, $response);
    $response->getBody()->write(PHP_EOL . 'AFTER');

    return $response;
});

/**
 * We instanciate the BridgeManager (this library)
 */
$bridgeManager = new BridgeManager($app);

/**
 * We start the Swoole server
 */
$http = new swoole_http_server("0.0.0.0", 8081);

/**
 * We register the on "start" event
 */
$http->on("start", function (\swoole_http_server $server) {
    echo sprintf('Swoole http server is started at http://%s:%s', $server->host, $server->port), PHP_EOL;
});

/**
 * We register the on "request event, which will use the BridgeManager to transform request, process it
 * as a Slim request and merge back the response
 *
 */
$http->on(
    "request",
    function (swoole_http_request $swooleRequest, swoole_http_response $swooleResponse) use ($bridgeManager) {
        $bridgeManager->process($swooleRequest, $swooleResponse)->end();
    }
);

$http->start();


Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].