PHP中的文件资源持久性 [英] File resource persistence in PHP

查看:107
本文介绍了PHP中的文件资源持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于MSN协议开发一个简单的聊天Web应用程序.服务器通过fsockopen ()返回的文件资源与MSN服务器通信.客户端通过XMLHttpRequest访问服务器.服务器首先登录,然后打印出客户端通过XMLHttpRequest对象的responseText ()接收到的联系人列表(格式为HTML表).

I'm developing a simple chat web application based on the MSN protocol. The server communicates with the MSN server through a file resource returned from fsockopen (). The client accesses the server via XMLHttpRequest. The server initially logs in, and prints out the contact list (formatted in an HTML table) which the client receives through the responseText () of the XMLHttpRequest object.

这是问题所在.必须使负责与MSN服务器通信的文件资源保持活动状态,以便所有与聊天相关的功能都可以正常工作(创建对话,跟踪脱机/联机状态更改等).但是,为了完成XMLHttpRequest,PHP脚本必须完成执行.这意味着在聊天会话进行过程中,客户端不会从XMLHttpRequest得到任何响应.

Here's the problem. The file resource that is responsible for communication with the MSN server must be kept alive in order for all chat related functions to work (creating conversations, keeping track of offline/online state changes, etc). However in order for the XMLHttpRequest to complete, the PHP script must finish execution. Which means the client will get no response from the XMLHttpRequest while the chat session is in progress.

更糟糕的是,文件资源无法序列化,这意味着我不能简单地将聊天会话存储在$_SESSION []占位符中.

Whats worse is a file resource cannot be serialized, meaning I cannot simply store the chat session in a $_SESSION [] placeholder.

所以,我的问题是,我是否可以将文件资源从一个文件转移"到另一个文件?

So, my question is, is there any possible way for me to 'transfer' a file resource from one file to another?

推荐答案

在大多数语言中,无法在应用程序之间传递文件句柄-AFAIK大多数操作系统也不允许这样做.

In most languages its not possible to pass file handles between applications - AFAIK most operating systems don't allow it either.

解决方案是保持服务器进程作为守护程序运行-这意味着它需要在Web服务器外部运行.

The solution is to keep the server process running as daemon - which means it needs to run outside of the webserver.

请参见

http://symcbean.blogspot.com /2010/02/php-and-long-running-processes.html

http://www.phpclasses.org/browse/package/5758.html

C.

这篇关于PHP中的文件资源持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆