{"id":21296923,"url":"https://github.com/reddec/scgi","last_synced_at":"2025-07-14T18:17:14.751Z","repository":{"id":30081229,"uuid":"33630811","full_name":"reddec/scgi","owner":"reddec","description":"SCGI client library for C++11 and linux. Exists packaging for Debian based systems","archived":false,"fork":false,"pushed_at":"2015-04-22T12:44:00.000Z","size":237,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T00:06:40.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/reddec.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}},"created_at":"2015-04-08T20:35:14.000Z","updated_at":"2015-04-22T12:44:01.000Z","dependencies_parsed_at":"2022-08-28T13:10:51.614Z","dependency_job_id":null,"html_url":"https://github.com/reddec/scgi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fscgi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fscgi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fscgi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fscgi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/scgi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243765022,"owners_count":20344521,"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":[],"created_at":"2024-11-21T14:31:00.371Z","updated_at":"2025-03-15T17:27:39.292Z","avatar_url":"https://github.com/reddec.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scgi\nSCGI client library for C++11 and linux. Exists packaging for Debian base systems\n\n# Requirements\n\n* C++11 compiler (tested on gcc-4.8)\n* UNIX/Linux tcp network subsystem\n* Cmake 2.8+\n\nFor services support\n\n* libjsoncpp-dev\n  * [Source repo](https://github.com/open-source-parsers/jsoncpp) \n  * [Ubuntu package](http://packages.ubuntu.com/search?keywords=jsoncpp\u0026searchon=names\u0026suite=trusty\u0026section=all)\n\n# How to build\n\n# Easy way\n\nJust copy to console and run (tested on Ubuntu 14.04 LTS x86_64; include services)\n\n```\ncd /tmp \u0026\u0026 \\\nrm -rf scgi \u0026\u0026 \\\ngit clone --recursive https://github.com/reddec/scgi \u0026\u0026 \\\ncd scgi \u0026\u0026 \\\n./build_debian.sh \u0026\u0026 \\\nsudo dpkg -i Release/scgi-*.deb \u0026\u0026 \\\ncd ../\n```\n\n# Manual build\n\n## Clone repository\n\n```\ngit clone https://github.com/reddec/scgi.git\ncd scgi\n```\n\n## Prepare Cmake files\n\n```\nmkdir Release\ncd Release\n```\n\n```\ncmake -DCMAKE_BUILD_TYPE=Release ..\n```\n\nor with services (required JsonCpp library with headers)\n\n\n```\ncmake -DWITH_SERVICES -DCMAKE_BUILD_TYPE=Release ..\n```\n\n## Build\n\n```\nmake\n```\n\n## For Debian based systems\n\nCreate .deb package after building by\n\n```\nmake package\n```\n\nand install via `dpkg -i` or something else\n\n************************\n\n# Direct SCGI request handling\n\nDocumentation will be in future...\n\nSee `SimpleAcceptor` class\n\n************************\n\n# Services\n\n\n## Frontend example configuration\n\n### NGinx\n\nWith service bound to UNIX socket `/tmp/myservice.sock`\n\n```\nhttp {\n   server {\n\tlocation ~ ^/myservice(?\u003cpath_info\u003e/.*) { \n         root /data/www;\n         include /etc/nginx/scgi_params;\n         scgi_param PATH_INFO $path_info; \n         scgi_pass unix:/tmp/myservice.sock;\n\t}\n    }\n}\n```\n\n\u003e **Important**\n\u003e\n\u003e NGinx does not provide PATH_INFO variable in SCGI context by default.\n\u003e \n\u003e So `scgi_param PATH_INFO $path_info` with regular expression in location is work around.\n\n### Lihgttpd\n\nWith service bound to UNIX socket `/tmp/myservice.sock`\n\nEnable module\n\n```\nserver.modules = (\n\t...\n    \"mod_scgi\",\n    ...\n)\n```\n\nAdd backend\n\n```\nscgi.server = (\n  \"/myservice\" =\u003e\n   ( \n     \"server1\" =\u003e (\n         \"socket\" =\u003e \"/tmp/myservice.sock\",\n         \"check-local\" =\u003e \"disable\"\n     )\n   )\n)\n```\n\n## Simple backend service\n\n### Target\n\nCRUD in memory some text data.\n\n\n### Code\n\n\n```c++\n\n#include \u003cscgi/service.h\u003e\n#include \u003cstring\u003e\n#include \u003cunordered_map\u003e\n\n\nclass DataKeeper : public scgi::service::ServiceHandler {\npublic:\n    DataKeeper() : scgi::service::ServiceHandler() {\n        register_method(\"update\")\n                .set_param(\"key\", Json::stringValue)\n                .set_param(\"value\", Json::stringValue)\n                .set_return_type(Json::nullValue)\n                .set_processor(\u0026DataKeeper::update, this);\n        register_method(\"get\")\n                .set_param(\"key\", Json::stringValue)\n                .set_return_type(Json::stringValue)\n                .set_processor(\u0026DataKeeper::get, this);\n        register_method(\"get_keys\")\n                .set_return_type(Json::arrayValue)\n                .set_processor(\u0026DataKeeper::get_keys, this);\n    }\n\nprotected:\n\n    bool update(scgi::RequestPtr request, const Json::Value \u0026query) {\n        std::string key = query[\"key\"].asString();\n        std::string value = query[\"value\"].asString();\n        content_[key] = value;\n        // Send zero data but with success code (200 OK)\n        request-\u003ebegin_response();\n        return true;\n    }\n\n    bool get(scgi::RequestPtr request, const Json::Value \u0026query) {\n        std::string key = query[\"key\"].asString();\n        auto key_iter = content_.find(key);\n        if (key_iter == content_.end()) return scgi::service::send_error(request, \"Key not found\");\n        scgi::service::send(request, Json::Value((*key_iter).second));\n        return true;\n    }\n\n    bool get_keys(scgi::RequestPtr request, const Json::Value \u0026query) {\n        Json::Value response;\n        for (auto \u0026kv:content_) response.append(kv.first);\n        scgi::service::send(request, response);\n        return true;\n    }\n\n    std::unordered_map\u003cstd::string, std::string\u003e content_;\n};\n\n\nbool stopped = false;\n\nvoid global_finalize(int) {\n    stopped = true;\n}\n\nint main() {\n    // Show used SCGI library version info\n    std::cout \u003c\u003c \"SCGI library: \" \u003c\u003c scgi::version() \u003c\u003c std::endl;\n    // Create connection manager. By default exists TCP or UNIX socket connection manager\n    auto connection_manager = io::UnixServerManager::create(\"/tmp/auth\");\n    // Create new service manager with specified connection manager\n    scgi::service::ServiceManager serviceManager(connection_manager);\n    // Set non-blocking mode\n    connection_manager-\u003eset_accept_timeout(1000);\n    // Add handlers\n    serviceManager.add_handler\u003cDataKeeper\u003e(\"/data\");\n    // Close service manager when SIGINT catched\n    serviceManager.set_on_idle([\u0026serviceManager]() {\n        if (stopped)serviceManager.stop();\n    });\n    // Show debug info. By default disabled\n    serviceManager.set_debug(true);\n    // Start loop\n    serviceManager.run();\n    return 0;\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fscgi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fscgi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fscgi/lists"}