简体   繁体   English

带有node.js守护进程的php网站

[英]php website with node.js daemon concurrently

I am creating a website in PHP (static, preprocessed pages and everything PHP-ish) BUT, 我正在用PHP创建一个网站(静态,预处理页面和所有PHP-ish)但是,

I would like to add some real-time functionalities like, say, a notification function, by using Node.JS with Socket.IO. 我想通过使用Node.JS和Socket.IO来添加一些实时功能,比如说通知功能。

So it's basically a PHP website but with a Node.js daemon that pushes some data via socket.io. 所以它基本上是一个PHP网站,但有一个Node.js守护进程通过socket.io推送一些数据。

I played around with it a bit, and all honestly, it doesn't seem that hard at all. 我玩了一下,老实说,它看起来并不那么难。

It's more of a curiosity, but do you think that it might be a good combination to have them together, by adding the Socket.IO javascript on the client to listen to server-side notifications? 这更像是一种好奇心,但是你认为通过在客户端添加Socket.IO javascript来监听服务器端通知,将它们组合在一起可能是一个很好的组合吗?

Thanks in advance. 提前致谢。


Also, I noticed that, when I require socket.io on the server, it puts the script on the client side too. 另外,我注意到,当我在服务器上需要socket.io时,它也将脚本放在客户端。 As I will not be using node to serve pages, I suppose that the script will not be included in the page. 因为我不会使用节点来提供页面,所以我认为该脚本不会包含在页面中。 Is there a way to include it manually? 有没有办法手动包含它?

Sorry for my English, I'm not native. 抱歉我的英语,我不是本地人。

If you don't need node to serve pages, you can just include socket.io and connect to the socket server. 如果您不需要节点来提供页面,则可以只包含socket.io并连接到套接字服务器。

In your client, add: 在您的客户端中,添加:

<script src="[server address]:[server port]/socket.io/socket.io.js"></script>

And then: 接着:

var socket = io.connect([server address]:[server port]);

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

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