阿帕奇转发请求到一个C ++程序 [英] Forwarding apache request to a c++ program

查看:218
本文介绍了阿帕奇转发请求到一个C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上找对如何处理这个问题的技巧和窍门。

I am basically looking for tips and tricks on how to approach that problem.

我有一个服务器软件(Linux)的,这是用C ++编写。我需要做的是
提供一些信息,即该软件的内部产生,经由
一个HTTP调用到Apache网络服务器。

I have a Server Software (Linux), which is written in C++. What I need to do is to provide some information, that is generated inside that software, via a http call to the apache webserver.

当然有可能将数据存储在数据库中,写一个servlet它,或者使用IPC来获取数据,但我想保持它的简单,在一个文件中捆绑在一起。同时,我想知道这个想法是可行的。

Of course it would be possible to store the data in the database and write a servlet for it, or use IPC to get the data, but I want to keep it simple and bundled in one file. And also I want to know if the idea would work.

因此​​,工作流将如下所示:
客户端 - > Apache服务器 - > C ++软件

So the workflow would look like: Client -> Apache Webserver -> C++ Software

有一个能够处理任何的Apache现有的库或东西 - > C ++连接?或者会是像刚才重定向请求到C ++中的插座,做手工?基本上是这样的Tomcat连接器。

Is there any existing library or something that could handle the Apache -> C++ connection? Or would it be something like just redirecting the request to a socket in c++ and do it manually? Basically something like the tomcat connector.

请注意,服务器软件在后台永久运行,并通过该呼叫不应当启动

Please note that the server software is running permanently in the background, and should not be "started" by the call

推荐答案

有几个选项。

CGI 是简单,已经撒手人寰。根据CGI,Web服务器会催生对每个Web请求一个单独的进程。当您在您的评论中提到,你可以写一个CGI脚本,使RPC调用你的C ++程序。

CGI is simple and has been around forever. Under CGI, the web server would spawn a separate process for every web request. As you mentioned in your comment, you could write a CGI script that makes RPC calls to your C++ program.

FastCGI的是CGI的替代;产卵,而不是一个单独的进程为每个Web请求,它定义了让Web服务器发送多个Web请求到一个长时间运行过程的协议。它的工作原理相当不错的web应用程序。但是,对于您的情况,那就是你有一个preexisting服务器需要添加一个web界面的过程,它可能无法正常工作为好;根据我有限的了解,Web服务器通常所期望的启动和停止长时间运行的FastCGI过程本身(响应传入的请求,服务器负载,空闲时间等),而不是连接到preexisting FastCGI进程。 (大多数服务器将让你重新配置这一点,我想,但它不是默认设置。)

FastCGI is an alternative to CGI; instead of spawning a separate process for every web request, it defines a protocol for letting the web server dispatch multiple web requests to a single long-running process. It works quite well for web applications. However, for your scenario, where you have a preexisting server process that needs to add a web interface, it may not work as well; based on my limited understanding, web servers typically expect to start and stop the long-running FastCGI processes themselves (in response to incoming requests, server load, idle time, etc.) instead of connecting to preexisting FastCGI processes. (Most servers would let you reconfigure this, I think, but it's not the default.)

您也可以随时嵌入类似猫鼬或的 CPP-NETLIB在C ++ 流程和设置Apache的代理请求给它。这可能是你最好的办法。 (猫鼬,例如,是极其容易嵌入。)

You can also always embed a web server like Mongoose or cpp-netlib in your C++ process and set up Apache to proxy requests to it. This might be your best approach. (Mongoose, for example, is extremely easy to embed.)

最后,你可以使用一个全面的Apache模块(无论是重新设计你的C ++服务器作为Apache模块或有一个Apache模块与C ++服务进行通信)。这可能比你想要做更复杂的,虽然也有像 CPPSERV现有项目是借此的方法。

Finally, you can use a full-fledged Apache module (either redesign your C++ server as an Apache module or have an Apache module to communicate with your C++ service). This is probably more complicated than you want to do, although there are existing projects like CPPSERV that take this approach.

这篇关于阿帕奇转发请求到一个C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆