{"id":13699970,"url":"https://github.com/pachico/slim-swoole","last_synced_at":"2025-05-04T18:33:54.781Z","repository":{"id":53781222,"uuid":"119850896","full_name":"pachico/slim-swoole","owner":"pachico","description":"Convenient library to run SlimPHP applications with Swoole","archived":true,"fork":false,"pushed_at":"2021-03-14T15:23:48.000Z","size":43,"stargazers_count":95,"open_issues_count":2,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-18T20:56:21.718Z","etag":null,"topics":["slim","slim-framework","swoole","swoole-framework"],"latest_commit_sha":null,"homepage":"https://github.com/pachico/slim-swoole/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pachico.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-01T15:01:21.000Z","updated_at":"2024-03-01T16:18:40.000Z","dependencies_parsed_at":"2022-08-24T08:50:40.935Z","dependency_job_id":null,"html_url":"https://github.com/pachico/slim-swoole","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachico%2Fslim-swoole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachico%2Fslim-swoole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachico%2Fslim-swoole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachico%2Fslim-swoole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pachico","download_url":"https://codeload.github.com/pachico/slim-swoole/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252382823,"owners_count":21739221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["slim","slim-framework","swoole","swoole-framework"],"created_at":"2024-08-02T20:00:46.657Z","updated_at":"2025-05-04T18:33:54.025Z","avatar_url":"https://github.com/pachico.png","language":"PHP","funding_links":[],"categories":["Framework Integration","Integration"],"sub_categories":[],"readme":"# slim-swoole\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pachico/slim-swoole/badges/quality-score.png?b=0.x-dev)](https://scrutinizer-ci.com/g/pachico/slim-swoole/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/pachico/slim-swoole/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/pachico/slim-swoole/?branch=master)\n[![Build Status](https://travis-ci.org/pachico/slim-swoole.svg?branch=master)](https://travis-ci.org/pachico/slim-swoole)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\n\nThis is a brige library to run [Slim framework](https://www.slimframework.com/) Slim framework applications using [Swoole engine](https://www.swoole.co.uk/).\n\n## Overview\n\nThe main purpose of this library is to easily run your already existing SlimPHP applications using Swoole Framework.\nIt 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.\n\nThe execution sequence is as follows:\n      \n1. You bootstrap your SlimPHP application as you would normally do.\n2. You instantiate the `BrigeManager` passing to it your SlimPHP application.\n3. You start Swoole's HTTP server.\n4. You bind to the `on('request')` event handler the `BridgeManager` instance which will:\n    1. Transform the Swoole request to a SlimPHP based on server and request attributes.\n    2. Process your request through SlimPHP's application stack (including middlewares)\n    3. Merge SlimPHP Response to Swoole Response\n    4. End the request.\n    All this is done under the hood, so you will just need to call:\n    \n```php\n$bridgeManager-\u003eprocess($swooleRequest, $swooleResponse)-\u003eend();\n```\n(See usage paragraph for a complete example.)\n\n**Caution**: it is still in development so any contribution and test will be more than welcome.\n\n## Requirements\n\n* PHP-CLI \u003e= 7.0 (Required by Swoole)\n* Swoole framework (this has been tested with version 1.10.1)\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require pachico/slim-swoole\n```\n\n## Usage\n\n``` php\n\u003c?php\n\nuse Pachico\\SlimSwoole\\BridgeManager;\nuse Slim\\Http;\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\n/**\n * This is how you would normally bootstrap your Slim application\n * For the sake of demonstration, we also add a simple middleware\n * to check that the entire app stack is being setup and executed\n * properly.\n */\n$app = new \\Slim\\App();\n$app-\u003eany('/foo[/{myArg}]', function (Http\\Request $request, Http\\Response $response, array $args) {\n    $data = [\n        'args' =\u003e $args,\n        'body' =\u003e (string) $request-\u003egetBody(),\n        'parsedBody' =\u003e $request-\u003egetParsedBody(),\n        'params' =\u003e $request-\u003egetParams(),\n        'headers' =\u003e $request-\u003egetHeaders(),\n        'uploadedFiles' =\u003e $request-\u003egetUploadedFiles()\n    ];\n\n    return $response-\u003ewithJson($data);\n})-\u003eadd(function (Http\\Request $request, Http\\Response $response, callable $next) {\n\n    $response-\u003egetBody()-\u003ewrite('BEFORE' . PHP_EOL);\n    $response = $next($request, $response);\n    $response-\u003egetBody()-\u003ewrite(PHP_EOL . 'AFTER');\n\n    return $response;\n});\n\n/**\n * We instanciate the BridgeManager (this library)\n */\n$bridgeManager = new BridgeManager($app);\n\n/**\n * We start the Swoole server\n */\n$http = new swoole_http_server(\"0.0.0.0\", 8081);\n\n/**\n * We register the on \"start\" event\n */\n$http-\u003eon(\"start\", function (\\swoole_http_server $server) {\n    echo sprintf('Swoole http server is started at http://%s:%s', $server-\u003ehost, $server-\u003eport), PHP_EOL;\n});\n\n/**\n * We register the on \"request event, which will use the BridgeManager to transform request, process it\n * as a Slim request and merge back the response\n *\n */\n$http-\u003eon(\n    \"request\",\n    function (swoole_http_request $swooleRequest, swoole_http_response $swooleResponse) use ($bridgeManager) {\n        $bridgeManager-\u003eprocess($swooleRequest, $swooleResponse)-\u003eend();\n    }\n);\n\n$http-\u003estart();\n\n\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email pachicodev@gmail.com instead of using the issue tracker.\n\n## Credits\n\n\n- [Mariano F.co Benítez Mulet](https://github.com/pachico)\n- [All Contributors](https://github.com/pachico/slim-swoole/graphs/contributors) \n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachico%2Fslim-swoole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpachico%2Fslim-swoole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachico%2Fslim-swoole/lists"}