简体   繁体   English

加快fsockopen

[英]speeding up fsockopen

I have a socket which connects to an irc server and sends some commands during the connection. 我有一个连接到irc服务器并在连接过程中发送一些命令的套接字。

Seems like this: 看起来像这样:

        $socket = @fsockopen(IRCIP, IRCPORT, $errno, $errstr, IMEOUT);
    stream_set_timeout($socket, TIMEOUT);
        fputs($socket, "SVSLIST\n");

But it takes a bit long (mostly, 0.5 second but sometimes its up to 1.5 second) Not to mention that both php script and the irc server works on the same machine. 但是它需要一些时间(大多数情况下是0.5秒,有时是1.5秒),更不用说php脚本和irc服务器都在同一台机器上工作了。

So i would like to ask how can i speed up this process? 所以我想问一下如何加快这个过程? I was using readfile with different kind of mechanism (building a httpd server as module in that irc server and redirect the readfile to do queries) to do that, it was pretty fast.. Is there a way to boost the speed? 我使用具有不同类型机制的readfile(在该irc服务器中将httpd服务器作为模块构建并重定向readfile进行查询)来做到这一点,这非常快。是否有提高速度的方法? Thanks. 谢谢。

The last parameter of fsockopen() is the timeout, set this to a low value to make the script complete faster, like this: fsockopen()的最后一个参数是超时,请将其设置为较低的值以使脚本更快地完成,如下所示:

$socket = @fsockopen(IRCIP, IRCPORT, $errno, $errstr, 0.1);

Also... you have to know that this code: 另外...您必须知道以下代码:

$socket = fsockopen('www.mysite.com', 80);

Is way slower than: 比以下方法慢:

$socket = fsockopen(gethostbyname('www.mysite.com'=, 80);

One last thing... if your script has to be run locally on the same machine of the IRC server, just use 127.0.0.1 to connect instead of the machine public IP address. 最后一件事...如果您的脚本必须在IRC服务器的同一台计算机上本地运行,则只需使用127.0.0.1即可连接,而不要使用计算机的公共IP地址。

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

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