php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78825 stream_socket_client works slower than except
Submitted: 2019-11-17 12:28 UTC Modified: 2019-11-18 15:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: vibbow at hotmail dot com Assigned: cmb (profile)
Status: Assigned Package: Performance problem
PHP Version: 7.3.11 OS: Windows Server 2019
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-11-17 12:28 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-17 12:33 UTC] 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 13:40 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: Sockets related +Package: Performance problem -Assigned To: +Assigned To: cmb
 [2019-11-17 13:40 UTC] 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 13:44 UTC] 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:48 UTC] vibbow at hotmail dot com
It can also be reproduced on Windows Server 2019
 [2019-11-17 22:42 UTC] cmb@php.net
-Status: Feedback +Status: Open
 [2019-11-18 12:35 UTC] cmb@php.net
Hmm, I cannot reproduce this when connecting to another machine on
the same network, where one runs Windows 10 1903 and the other
Windows 10 1909 (tested both directions).  Tested with PHP 7.3.11
x64 NTS.
 [2019-11-18 15:22 UTC] vibbow at hotmail dot com
That'e weird, I can consistent reproduce this issue.


I'll try to replicate my environment on a cloud server and try again.
 [2019-11-18 19:26 UTC] vibbow at hotmail dot com
I tried to reproduce this issue on 4 different environment, 3 environment can reproduce this issue, 1 environemtn can't reproduce this issue.

First I enhanced the test script a little bit, so I can see the overall trend.
https://gist.github.com/vibbow/8909ffc9990023129562e8971fe30f7d

This script will return four number at end of test:
1000 | 0 | 239 | 761
1st and 2nd number are latency below & above 5ms when using socket_create
3rd and 4th number are latnecy below & avobe 5ms when using stream_socket_client

Next is my four enviroment and test results:

 - First environment:
Two Physical Machine
Machine One
    Running Windows 10 1909 x64 ´╝łAgent A)
Machine Two
    Running Windows Server 2019 with Hyper-V enabled (Agent B)
    Running Ubuntu Server 19.10 as Hyper-V Guest (Agent C)

Result:
Agent A -> Agent C
    992 | 8 | 157 | 843
Agent B -> Agent C
    1000 | 0 | 106 | 894
Agent B -> Agent A
    994 | 6 | 53 | 947


- Second environment:
One Physical Machine
Machine One:
    Running VMware ESXi 6.7
    Running Windows Server 2019 as ESXi Guest (Agent A)
    Running Ubuntu Server 18.04 as ESXi Guest (Agent B)

Result:
Agent A -> Agent B
    1000 | 0 | 239 | 761


- Third environment:
One Physical Machine
Machine One:
    Running Windows 10 LTSC 2019 with Hyper-V Enabled (Agent A)
    Running Ubuntu Server 18.04 as Hyper-V Guest (Agent B)

Result:
Agent A -> Agent B
    1000 | 0 | 23 | 977


- Fourth environment:
Two VIRTUAL machine (on vultr.com)
VM1: Windows Server 2019 (Agent A)
VM2: Ubuntu Server 19.04 (Agent B)

Result:
Agent A -> Agent B
    999 | 1 | 1000 | 0
 [2019-11-18 19:41 UTC] vibbow at hotmail dot com
I'm using minimum PHP config to reproduce this issue:

By copy php.ini-production config file with add following two lines:

extension_dir = ".\ext\"
extension = sockets
 [2019-11-18 19:51 UTC] vibbow at hotmail dot com
I'll try to run this test on two physical machine without any virtualization installed.
 [2019-11-18 23:03 UTC] vibbow at hotmail dot com
I can get this reproduced on my laptop without any virtualization software installed, so it's not virtualizaiton software related issue.

Still try to figure out what's the key point to affect this.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 21:01:24 2019 UTC