PHP-有人可以为我解释pfsockopen函数吗? (永久插座) [英] PHP - Can someone explain the pfsockopen function for me? (persistent socket)

查看:64
本文介绍了PHP-有人可以为我解释pfsockopen函数吗? (永久插座)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从PHP.net:

http://www.php.net/manual/en/function.pfsockopen.php

我了解此功能可以完成的要点,但是我仍然不清楚该功能是否可以实现我想要的功能.这是我的情况:

I understand the gist of what this function accomplishes, but I'm still unclear as to whether this will accomplish what I'd like it to. Here is my scenario:

我有一个大型的PHP应用程序,许多用户同时使用它.在该应用程序中,我正在打开到远程服务器的TCP套接字以记录消息等.我希望我可以利用pfsockopen来减少需要打开的连接数.例如,user1登录-套接字打开. User2登录,没有打开套接字,因为他可以背负"在user1打开的套接字上.

I have a large PHP application that is used by many users simultaneously. Within the application, I'm opening a TCP socket to a remote server for logging messages, etc... It was my hope that I might be able to leverage pfsockopen in order that many fewer connections would need to be opened. For example, user1 signs in - socket opens. User2 signs in, no socket is opened because he can "piggyback" on the socket opened by user1.

这可能吗?

推荐答案

pfsockopen确实会在脚本结束时使套接字保持打开状态,从而允许将其从请求重用到另一个请求,从而有效地减少了像您这样的连接会期望的.但是,这并不与所有SAPI兼容.

pfsockopen will indeed keep the socket open when the script ends, allowing it to be re-used from a request to another, effectively opening less connections like you would expect. However, this is not compatible with all SAPIs.

持续性在每个进程的基础上发生.这样,在CLI中运行的pfsockopen会在每次执行时关闭并重新打开套接字,因为CLI脚本是在单个进程中执行的,该进程启动,打开套接字并结束(将套接字与进程一起关闭)

The persistence occurs on a per-process basis. As such, pfsockopen ran in a CLI SAPI will close and re-open a socket at every execution, because the CLI script is executed in a single process that starts, open a socket and ends (closing the socket along with the process).

在CGI模式下,每个脚本只有一个进程,这也是事实.

In CGI mode with one process per script, this is also true.

对于Apache SAPI,这取决于使用哪种类型的多处理模块(MPM). mpm-prefork会在每次请求时生成一个新进程,因此很可能不支持该进程.但是,mpm-worker会生成线程,因此它可能在那里工作. mpm-winnt是Windows多线程MPM的变体,因此它也应该工作.

With the Apache SAPI, it depends what type of multi-processing module (MPM) is in use. mpm-prefork spawns a new process at every request, so it most likely doesn't support it. mpm-worker however, spawns threads, so it will probably work there. mpm-winnt is a Windows variant of a multi-threaded MPM, so it should work too.

最糟糕的情况是该调用将作为普通的fsockopen调用执行.

The worst that can happen is that the call will be executed as a normal fsockopen call.

这篇关于PHP-有人可以为我解释pfsockopen函数吗? (永久插座)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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