{"id":18523120,"url":"https://github.com/taymindis/fcgi-function","last_synced_at":"2025-04-09T11:31:27.959Z","repository":{"id":132371988,"uuid":"84576937","full_name":"Taymindis/fcgi-function","owner":"Taymindis","description":"A cross-platform module to writing C/C++ service for nginx.","archived":false,"fork":false,"pushed_at":"2019-05-16T07:09:37.000Z","size":370,"stargazers_count":37,"open_issues_count":0,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T05:13:28.865Z","etag":null,"topics":["c","cjson","fastcgi","indexing","json","lock-free","nginx","webserver"],"latest_commit_sha":null,"homepage":"https://www.nginx.com/resources/wiki/modules/fcgi_function/","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/Taymindis.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":"2017-03-10T16:03:34.000Z","updated_at":"2024-12-26T23:02:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"8953fb42-bc76-469a-80c0-73fdf0af6a48","html_url":"https://github.com/Taymindis/fcgi-function","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Ffcgi-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Ffcgi-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Ffcgi-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Ffcgi-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Taymindis","download_url":"https://codeload.github.com/Taymindis/fcgi-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031409,"owners_count":21036393,"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":["c","cjson","fastcgi","indexing","json","lock-free","nginx","webserver"],"created_at":"2024-11-06T17:34:18.088Z","updated_at":"2025-04-09T11:31:27.952Z","avatar_url":"https://github.com/Taymindis.png","language":"C","readme":"# fcgi-function\nfcgi Function is a C/CPP language based interface, which build on top of FastCGI with built in functional handler support, it also provided useful collection tools to enhance the facilities. It can be integrated with Nginx Fastcgi module\n\n## How it works\n![Image of architecture](/images/fcgi_func_architecture.png)\n\n\n## Prerequisition Installed\nNginx -- https://www.nginx.com/\n\nfcgi library -- https://github.com/FastCGI-Archives/FastCGI.com\n\ncmake and make\n\n### Supported OS: LINUX, MAC OSX, and Windows\n\n## Clone the Repository Recursively\ngit clone --recursive https://github.com/Taymindis/fcgi-function.git\n\n## How to Build\n\n### Just Include ffunc.h and ffunc.c in your project, simplest way ( applicable to Linux, Darwin and Windows platforms )\n#### Build sample \n\u003e gcc profile_service.c ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic\n\n\u003e g++ profile_service.cpp ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic\n\n\u003e g++ -std=c++11 -I/home/xxx/cpplib/spdlog-0.17.0/include -DSPDLOG_FMT_PRINTF service_with_spdlog.cpp ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic\n\n### when you type \n\n\u003e ./simple_service\n\nit will result:-\n\n```bash\n\nService starting\nsock_port=2005, backlog=16\ntotal function = 3\n64 threads in process\nSocket on hook 2005\n\n```\n\n\nRunning on background by setting `ffunc_conf-\u003edaemon = 1 `, see example for mode details\n```c\nint ffunc_main(int argc, char *argv[], ffunc_config_t *ffunc_conf) {\n  ffunc_conf-\u003esock_port = 2005;\n  ffunc_conf-\u003ebacklog = 160;\n  ffunc_conf-\u003emax_thread = 64;\n  ffunc_conf-\u003edaemon = 1; // run as daemon\n  ffunc_parse_function(ffunc_conf, \"getProfile\", \"postError\", \"postProfile\");\n  return 0;\n}\n```\n\n### Running on valgrind (performance will impact)\n\u003e valgrind --leak-check=full --show-leak-kinds=all --trace-children=yes ./simple_service\n\n### Edit the nginx.conf in your nginx config folder by append in your server block:-\n\n\tlocation /getProfile {\n      add_header Allow \"GET, POST, HEAD\" always;\n      if ( $request_method !~ ^(GET|HEAD)$ ) {\n        return 405;\n      }\n      include /etc/nginx/fastcgi_params;\n      fastcgi_param FN_HANDLER getProfile;\n      fastcgi_pass 127.0.0.1:2005;\n    }\n\n    location /postProfile {\n      add_header Allow \"GET, POST, HEAD\" always;\n      if ( $request_method !~ ^(POST)$ ) {\n        return 405;\n      }\n       include /etc/nginx/fastcgi_params;\n      fastcgi_param FN_HANDLER postProfile;\n      fastcgi_pass 127.0.0.1:2005;\n    }\n\n### Edit the httpd.conf in your httpd config folder by append in your block \n\n```httpd\n\u003cLocation \"/getProfile\"\u003e\n    # Timeout values are in seconds\n    ProxyPass \"fcgi://127.0.0.1:2005\" connectiontimeout=300 timeout=300\n    ProxyPassReverse \"fcgi://127.0.0.1:2005\"\n    SetEnv  FN_HANDLER \"getProfile\"\n\u003c/Location\u003e\n\n```\n\n***You will see the FN_HANDLER is function name mapping with the function inside simple_service code, the fastcgi port 2005 is the service you start with(please look at step 10 for more details.***\n\n### start the nginx/httpd server \n\n### Using apache benchmark for get request load test\n\n\u003e ab -c 100 -n 10000 http://127.0.0.1:80/getProfile\n\n\n#### For post request load test\n\n\u003e ab -p \"payload.txt\" -T application/json -c 100 -n 10000 http://127.0.0.1:80/postProfile\n\n*the payload.txt is inside the root directory*\n\n\n### shutdown the background instance \n\n##### kill the process by using `kill -2 \u003cpid\u003e`, *please do not use -9 as it will direct kill the process, unless -2 is not working*\n#### for valgrind log, you will get the summary report after `kill -2 \u003cpid\u003e` \n\n\n### Example of how to build a docker image \n\n```bash\ncd DockerExample\ndocker build -t nginx_ffunc -f Dockerfile_ngx_ffunc .\ndocker run -d -v ~/fcgi-function/DockerExample:/tmp -p 80:80 --name testffunc nginx_ffunc\ncurl \"http://127.0.0.1/getProfile\"\n```\n\n\n### Logging Recommendation\nDue to built in logging mechanism will slow down the process speed, suggested to use third party logging mechanism for your application layer such as:-\n\n[C++ spdlog](https://github.com/gabime/spdlog)\n\n[C++ g3log](https://github.com/KjellKod/g3log)\n\n[C mini-async-log](https://github.com/RafaGago/mini-async-log)\n\n\n## Please contact minikawoon2017@gmail.com for More End to End tier project examples.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaymindis%2Ffcgi-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaymindis%2Ffcgi-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaymindis%2Ffcgi-function/lists"}