简体   繁体   English

PHP <-> node.js通信

[英]php <-> node.js communication

What is the Best way to communicate in between'em when :- 在以下情况下,他们之间进行交流的最佳方式是什么?

  1. I need to restart node.js app (or Update configs) from php 我需要从php重新启动node.js应用程序(或更新配置)

I do know about D-node. 我确实了解D节点。 But is D-node good to use in my case ? 但是在我的情况下D节点好用吗? I can have 100s of node.js apps 我可以有100个node.js应用

Your question is opinion based... 您的问题是基于意见的...

If you have a complex system with hundreds of applications in multiple languages (PHP + JS in your case) 如果您有一个复杂的系统,其中包含数百种使用多种语言的应用程序(您的情况下为PHP + JS)

  • Define messages so that they can communicate to each other. 定义消息,以便它们可以彼此通信。
  • Choose a common tool to serialize, unserialize messages (JSON, Avro, Protobuf, XML...) 选择一个通用的工具来序列化和反序列化消息(JSON,Avro,Protobuf,XML ...)
  • Choose a messaging system that suits your needs (RabbitMQ, ZeroMQ, ActiveMQ, ...) 选择适合您需求的消息传递系统(RabbitMQ,ZeroMQ,ActiveMQ等)
  • Decide which app does which task and a global messaging architecture with patterns that you did not invent (i like zmq documentation for that matter, but you should also read the RabbitMQ doc). 确定哪个应用程序执行哪个任务以及具有您未发明的模式的全局消息传递体系结构(我喜欢zmq文档,但您也应该阅读RabbitMQ文档)。

Another great tool is Celery (from the python world). 另一个很棒的工具是Celery(来自python世界)。 You won't be able to use it, but its documentation is a very good read. 您将无法使用它,但是它的文档非常不错。

Everything else wont work. 其他所有的东西都行不通。 If you start having a PHP script restarting another one, that does some task, then calls a bash script, you will end up spending 10 times the effort debugging. 如果您开始使用PHP脚本重新启动另一个脚本,该脚本执行某些任务,然后调用bash脚本,则最终您将花费10倍的精力进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM