Bug #78825 [Com]: stream_socket_client works slower than except

From: Date: Sun, 17 Nov 2019 13:48:24 +0000
Subject: Bug #78825 [Com]: stream_socket_client works slower than except
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223763@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78825&edit=1

 ID:                 78825
 Comment by:         vibbow at hotmail dot com
 Reported by:        vibbow at hotmail dot com
 Summary:            stream_socket_client works slower than except
 Status:             Feedback
 Type:               Bug
 Package:            Performance problem
 Operating System:   Windows Server 2019
 PHP Version:        7.3.11
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

It can also be reproduced on Windows Server 2019


Previous Comments:
------------------------------------------------------------------------
[2019-11-17 13:44:24] vibbow at hotmail dot com

I can get this reproduced on:

Windows 10 1909 x64

PHP 7.3.11 x64 nts
PHP 7.3.1 x64 nts
PHP 7.2.9 x64 nts
PHP 5.6.9 x64 nts

If stream_socket_client connect to a local interface ip address, then everything works fine.

It can only reproduced by connect to another PC on same network.

------------------------------------------------------------------------
[2019-11-17 13:40:06] cmb@php.net

I can't reproduce this; I get something like:

0.83518028259277
0.43416023254395

Similar if I use hrtime() for measuring the performance.

Which exact PHP version do you use?

------------------------------------------------------------------------
[2019-11-17 12:33:52] vibbow at hotmail dot com

This issue can be reproduced on Windows platform only, on Linux everything works fine.

This issue may also affect php extension who used php_stream API, like phpredis.

------------------------------------------------------------------------
[2019-11-17 12:28:30] vibbow at hotmail dot com

Description:
------------
In my test script, I use two method to create a tcp connection (to another pc in LAN), one is
socket_connect, another is stream_socket_client.

Since those two code snips doing the same thing, they should have same time cost.

But on Windows platform, stream_socket_client are must slower than except.

socket_create are using less 1ms in average,
stream_socket_client are using around 10ms in average.

Can be reproduced from PHP 7.1 to 7.3

Can be reproduced on Windows 2019 & Windows 10 1909.



Test script:
---------------
<?php

$begin = microtime(true);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, '192.168.163.110', 6379);
$end = microtime(true);
echo ($end - $begin) * 1000 . PHP_EOL;


$begin = microtime(true);
$fp = stream_socket_client("tcp://192.168.163.110:6379");
$end = microtime(true);
echo ($end - $begin) * 1000 . PHP_EOL;

Expected result:
----------------
socket_create & stream_socket_client should use similier time cost

Actual result:
--------------
D:\Websites>php test.php
1.1060237884521
10.412216186523

stream_socket_client use 10 times time than socket_create


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78825&edit=1


Thread (24 messages)

« previous php.bugs (#223763) next »