我们正在开发一个实时应用程序,我们正在将 nginx 推送流模块用于 websockets 部分.首先,数据从客户端发送到 php 脚本,该脚本执行一些身份验证并将所需信息存储在数据库中,然后将信息推送到 nginx,然后将其发送给特定套接字上的订阅用户.经常会出现从该脚本向本地 nginx 发出超过 30 个 http 请求的情况(我不确定这是一件坏事吗?).
We are developing a realtime app and we are using nginx push stream module for a websockets part. Firstly, data is send from a client to a php script that does some authentication and stores needed information in database and then pushes information to nginx that later sends it to a subscribed users on a specific sockets. Quite often there will be situations when there are more that 30 http requests made from this script to local nginx (which I am not exactly sure is a bad thing?).
问题
是否可以在没有 http 请求的情况下将信息从 php 发送到 nginx?有什么方法可以让我的 php 脚本与 nginx 通信?处理这种通信的最佳做法是什么?每个 php 脚本发送 30+ 个 http 请求是一个好习惯吗?
Question
Is it possible to send information from php to nginx without http requests? Is there any way that my php script can communicate with nginx? What is a best practise to handle this kind of communications? Is sending 30+ http requests per php script a good practise?
我已经阅读了一些 AMQP 解决方案,但没有找到 nginx 是来自 rabbitmq 消息的消费者的信息.
I have read towards some AMQP solutions but haven't found information where nginx is a consumer of messages from rabbitmq.
如果有不清楚的地方,我很乐意提供任何其他信息.
I will gladly provide any additional information if something is not clear.
我假设如下:
当前工作流程:
OP 问题:
命令行 php 脚本使用 http 协议与 Nginx 服务器端脚本通信的效率,由于通信发生在同一服务器内,这可能会有点过分.
Efficiency of command line php script communicating with Nginx server side script using http protocol, which maybe overkill as the communication happen within the same server.
提案 1
提案 2
将您的命令行 php 脚本组合到 Nginx 服务器端脚本中,并为其创建一个 Web 界面.当前命令行用户将登录网页以控制他们使用命令行工具执行此操作的过程.
Combine your command line php script into the Nginx server side script, and create a web interface for it. Current command line user will login webpage to control the process they used to do it with command line tool.
专业人士:不再有脚本间/进程间通信.整个工作流程在一个过程中.这可能在未来也更具可扩展性,因为多个用户可以通过 Web 界面登录并远程处理该过程.此外,它们不需要操作系统级别的帐户.
Pro: No more inter-scripts/inter-process communication. The whole work flow is in one process. This maybe more scalable for the future also, as multiple users can log in through web interface and handle the process remotely. Additionally, they do not require OS level accounts.
缺点:可能需要更多的开发时间.(但你只需要维护一个代码库而不是两个.)
Con: May need more development time. (But you only have to maintain one code base instead of two.)
这篇关于在没有 http 的情况下从同一服务器上的 php 向 ngnix 发送信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!