简体   繁体   中英

speeding up fsockopen

I have a socket which connects to an irc server and sends some commands during the connection.

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.

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? Thanks.

The last parameter of fsockopen() is the timeout, set this to a low value to make the script complete faster, like this:

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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