[英]Socket.io and PHP integration
I have a socket. 我有一个插座。 I login to the socket from header.php
. 我从header.php
登录到套接字。 I'm calling header.php
from all of my pages like this: 我从我的所有页面中调用header.php
,如下所示:
<?php
require_once("header.php");
?>
When I load all pages like this my socket is going to disconnect and then reconnect. 当我像这样加载所有页面时,我的套接字将断开连接,然后重新连接。 I want to login just once on the socket but I don't know how can I do this. 我只想在套接字上登录一次,但是我不知道该怎么做。 How can I prevent it from disconnecting and reconnecting? 如何防止其断开和重新连接?
header.php
JavaScript code block: header.php
JavaScript代码块:
<script src='http://xxx.xxx.xx.xx:1xx0/socket.io/socket.io.js'></script>
<script>
var socket = io.connect( "http://xxx.xxx.xx.xx:1xx0/");
</script>
Short answer is you can't. 简短的答案是你不能。 Web server starts each page load fresh. Web服务器将重新启动每个页面加载。 If you want a persistent connection with your socket maybe do that in a php cli app on the server and communicate with the browser using websockets etc. 如果您想与套接字建立持久连接,则可以在服务器上的php cli应用程序中执行此操作,然后使用websockets等与浏览器进行通信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.