简体   繁体   English

在php中为每个客户端保持连接打开

[英]Keeping a connection open for each client in php

I have a C++ backend application coded over a TCP socket, to which I connect PHP to. 我有一个通过TCP套接字编码的C ++后端应用程序,我将PHP连接到该套接字。 The problem is that the connection is closed on every refresh, change page, etc. I would like to keep the connection open for each client, doing something like $_Session does. 问题是每次刷新,更改页面等都会关闭连接。我想为每个客户端保持连接打开,像$ _Session这样做。

This is not really what PHP (or the whole of web-based applications and services, for that matter) are meant for. 这并不是PHP(或整个基于Web的应用程序和服务)的意思。 It also means begging for resource problems before long because big PHP processes will be running simultaneously, instead of running for a quick moment on each request. 这也意味着不久就会出现资源问题,因为大型PHP进程将同时运行,而不是在每个请求上快速运行。

What speaks against making use of the normal session mechanisms from within your app (ie dealing with session ID cookies) like other clients? 什么反对在您的应用程序中使用正常的会话机制(即处理会话ID cookie)与其他客户端一样?

I'm no expert in C++ but I'm sure that most http libraries can deal with a "cookie jar", which is essentially all you need to persist a session from within your client application. 我不是C ++方面的专家,但我确信大多数http库都可以处理“cookie jar”,这基本上就是你需要在客户端应用程序中持久保存会话。

While I don't know much about PHP, I can tell you that web browsers aren't designed to hold continuous connections. 虽然我对PHP知之甚少,但我可以告诉你,Web浏览器不是为了保持连续连接而设计的。 They have to reconnect every time they make a HTML request. 他们每次发出HTML请求时都必须重新连接。

The HTTP standard specifies that the server will disconnect from the client after it has finished sending it it's request. HTTP标准指定服务器在完成发送请求后将断开与客户端的连接。

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

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