Edit report at https://bugs.php.net/bug.php?id=78825&edit=1
ID: 78825
Updated by: cmb@php.net
Reported by: vibbow at hotmail dot com
Summary: stream_socket_client works slower than except
-Status: Open
+Status: Feedback
Type: Bug
-Package: Sockets related
+Package: Performance problem
Operating System: Windows Server 2019
PHP Version: 7.3.11
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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?
Previous Comments:
------------------------------------------------------------------------
[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