{"id":25953579,"url":"https://github.com/ody-dev/ody-swoole","last_synced_at":"2025-03-04T15:29:17.112Z","repository":{"id":279958433,"uuid":"940262151","full_name":"ody-dev/ody-swoole","owner":"ody-dev","description":" Swoole HTTP server, cache and websockets. ","archived":false,"fork":false,"pushed_at":"2025-02-28T12:09:23.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T18:49:35.930Z","etag":null,"topics":["framework","php","swoole","websocket"],"latest_commit_sha":null,"homepage":"","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/ody-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-27T21:58:16.000Z","updated_at":"2025-02-28T12:09:15.000Z","dependencies_parsed_at":"2025-02-28T18:49:40.078Z","dependency_job_id":"66f53986-573c-4aa9-8b02-69b9d965889e","html_url":"https://github.com/ody-dev/ody-swoole","commit_stats":null,"previous_names":["odysee-dev/ody-swoole"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ody-dev%2Fody-swoole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ody-dev%2Fody-swoole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ody-dev%2Fody-swoole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ody-dev%2Fody-swoole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ody-dev","download_url":"https://codeload.github.com/ody-dev/ody-swoole/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241871484,"owners_count":20034475,"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":["framework","php","swoole","websocket"],"created_at":"2025-03-04T15:29:15.505Z","updated_at":"2025-03-04T15:29:17.104Z","avatar_url":"https://github.com/ody-dev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ody/swoole\nSwoole support classes for ODY framework\n\n## TODO/roadmap\n\n- [x] Swoole HTTP server\n- [ ] Websockets\n- [ ] Connection pools (MySQL, Redis,...)\n- [ ] Cache\n- [ ] Documenation\n\n### Websockets\nWIP\n\n```php\n\\Ody\\Swoole\\Websockets\\Server::init('0.0.0.0', 9502)  // Host \u0026 port are nullable, will default to app.websockets config\n    -\u003ecreateServer()\n    -\u003estart();\n```\n\n### Hot reloading\n```php\n$serverState = ServerState::getInstance();\n(new Process(function (Process $process) {\n    $serverState-\u003esetWatcherProcessId($process-\u003epid);\n    (new Watcher())-\u003estart();\n}))-\u003estart();\n```\n\nThe `Watcher` class's constructor accepts a paths parameter, this is an array of\nfolder locations that need to be watched for changes. If no paths are specified the \npaths in `config/server.php` will be used. \n\nThis class uses a helper function `base_path()` to determine the base path of your project.\n\n```php\ndefine('PROJECT_PATH' , realpath('./')); // Add this global constant to one of your bootstrap files.\nfunction base_path(string $path = null): string\n{\n    return realpath(PROJECT_PATH) . \"/$path\";\n}\n```\n\n### Context manager\nWhen using coroutines it is possible to assign values to the coroutine context.\nThese values can be called from anywhere in the app.\n\n```php\n// Saves the GET query string to the coroutine context\nContextManager::set('_GET', (array)$request-\u003eget);\n\n// Get the `_GET` parameters\nContextManager::get('_GET');\n\n// Remove a parameter from the coroutine context\nContextManager::unset('_GET');\n```\n\n### Cache\nPlanned feature\n\n### Server.php config file\n```php\n\u003c?php\n\nreturn [\n    'mode' =\u003e SWOOLE_BASE,\n    'host' =\u003e '127.0.0.1',\n    'port' =\u003e 9501 ,\n    'sockType' =\u003e SWOOLE_SOCK_TCP,\n    'additional' =\u003e [\n        'worker_num' =\u003e env('APP_WORKER_COUNT' , swoole_cpu_num() * 2) ,\n        /*\n         * log level\n         * SWOOLE_LOG_DEBUG (default)\n         * SWOOLE_LOG_TRACE\n         * SWOOLE_LOG_INFO\n         * SWOOLE_LOG_NOTICE\n         * SWOOLE_LOG_WARNING\n         * SWOOLE_LOG_ERROR\n         */\n        'log_level' =\u003e SWOOLE_LOG_DEBUG ,\n        'log_file' =\u003e storagePath('logs/ody.log') ,\n        'open_http_protocol' =\u003e true,\n    ],\n\n    'ssl' =\u003e [\n        'ssl_cert_file' =\u003e null ,\n        'ssl_key_file' =\u003e null ,\n    ] ,\n\n    /*\n     * The following services are created for better performance \n     * in the program, only one object is created from them and \n     * they can be used throughout the program\n     */\n    'services' =\u003e [] ,\n\n    /*\n     * Files and folders that must be changed in real time\n     */\n    'watcher' =\u003e [\n        'App',\n        'config',\n        'database',\n        'composer.lock',\n        '.env',\n    ] \n];\n```\n\n### Websockets.php config file\n```php\n\u003c?php\n\nreturn [\n    'host' =\u003e env('WEBSOCKET_HOST', '127.0.0.1'),\n    'port' =\u003e env('WEBSOCKET_PORT', 9502),\n    'sock_type' =\u003e SWOOLE_SOCK_TCP,\n    /**\n     * Overwrite websocket events with your own callable methods (WIP)\n     */\n    'callbacks' =\u003e [\n        Event::ON_HAND_SHAKE =\u003e [\\Ody\\Swoole\\Websockets\\Server::class, 'onHandShake'],\n        Event::ON_MESSAGE =\u003e [\\Ody\\Swoole\\Websockets\\Server::class, 'onMessage'],\n        Event::ON_CLOSE =\u003e [\\Ody\\Swoole\\Websockets\\Server::class, 'onClose'],\n        Event::ON_REQUEST =\u003e [\\Ody\\Swoole\\Websockets\\Server::class, 'onRequest'],\n    ],\n    \"additional\" =\u003e [\n        \"worker_num\" =\u003e env('APP_WEBSOCKET_WORKER_NUM', swoole_cpu_num() * 2),\n    ]\n];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fody-dev%2Fody-swoole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fody-dev%2Fody-swoole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fody-dev%2Fody-swoole/lists"}