阿帕奇 - 处理的TCP连接,而不是HTTP请求 [英] Apache - handling TCP connections, but not HTTP requests

查看:254
本文介绍了阿帕奇 - 处理的TCP连接,而不是HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GPS装置,可以通过TCP连接发送数据,但我没有修改它发送所以它会来我的服务器在HTTP请求的形式信息的能力 - 它只能在predefined格式发送邮件。

I have a GPS unit that can send data over a TCP connection, but I don't have the ability to modify the message that it sends so it would come to my server in the form of an HTTP request - it can only send a message in a predefined format.

所以,我有以下问题:

1)是否有可能让Apache处理并不在HTTP请求的形式来建立TCP连接,并具有发送一个PHP脚本处理的消息?

1) Is it possible to have Apache handle a TCP connection that doesn't come in the form of an HTTP request, and have the message that is sent be processed by a PHP script?

2)如果第1条是不可能的,你会怎么推荐我处理数据被发送到我的服务器?

2) If #1 isn't possible, how would you recommend I handle the data being sent to my server?

我将可能有数百个,如果不是数千,这些GPS设备将数据发送到我的服务器,所以我需要一个有效的方式来处理所有的连接进来(这就是为什么我想要的Apache或其他一些生产有价值的服务器处理TCP连接)。我想是能够处理发送过来用PHP连接的消息,因为这是我的应用程序的其余部分运行在,我需要插入送入数据库中的数据(和PHP是这样做真的好之类的话)。

I will potentially have hundreds, if not thousands, of these GPS units sending data to my server so I need an efficient way to handle all of the connections coming in (which is why I wanted Apache or some other production worthy server to handle the TCP connections). I would like to be able to deal with the message sent over the connection with PHP since that is what the rest of my application runs on, and I will need to insert the data sent into a database (and PHP is really good at doing that kind of thing).

在的情况下它的事项,GPS单元可以通过UDP连接发送数据,但是从我已阅读Apache不使用UDP连接工作。

In case it matters, the GPS unit can send data over a UDP connection, but from what I have read Apache doesn't work with UDP connections.

任何建议将受到欢迎。

Any suggestions would be welcome.

推荐答案

使用Apache,因为它是使用核弹,当鞭炮就够了是不实际的。创建一个PHP服务器的Linux上的xinetd的帮助非常简单。

Using Apache wouldn't be practical as it's using a nuclear bomb when a firecracker will suffice. Creating a PHP server is quite simple on Linux with the help of xinetd.

修改 / etc / services中假设你希望你的服务端口上运行56789.在的/ etc /服务,添加一行:

gpsservice   56789/tcp

/etc/xinet.d / ,创建一个名为 gpsservice 文件:

In /etc/xinet.d/, create a file named gpsservice:

service gpsservice 
{
    socket_type             = stream
    protocol                = tcp
    wait                    = no
    user                    = yourusername
    server                  = /path/to/your/script
    log_on_success          = HOST PID
    disable                 = no
}

创建你的PHP脚本(通过chmod将其视为可执行文件):

#!/usr/bin/php
<?php
// do stuff
?>

重新启动xinetd 服务的xinetd重启

Restart xinetd service xinetd restart

您现在可以用PHP编写的快速TCP服务器。

You now have a quick TCP server written in PHP.

这篇关于阿帕奇 - 处理的TCP连接,而不是HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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