Bug #81304 [Nab]: simple socket listen and receive scripts transfer incomplete data

From: Date: Sun, 29 May 2022 20:34:43 +0000
Subject: Bug #81304 [Nab]: simple socket listen and receive scripts transfer incomplete data
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241619@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81304&edit=1 ID: 81304 Updated by: requinix@php.net Reported by: odarcan at gmail dot com Summary: simple socket listen and receive scripts transfer incomplete data Status: Not a bug Type: Bug Package: Sockets related Operating System: linux PHP Version: 7.4.21 Block user comment: N Private report: N New Comment: The main problem here seems to be that you have some knowledge about networking but aren't aware that you're missing out on a lot more. https://www.google.com/search?q=socket+read+write+buffering Previous Comments: ------------------------------------------------------------------------ [2022-05-29 13:24:06] odarcan at gmail dot com Also in a variant of this where the data is sent in a loop, making the buffer size 10000 and adding a usleep(10000) to the loop SOLVES the problem I dont see how this is not a php problem something is writing somewhere too fast, whatever that is Id like to know what and how I can prevent it. ------------------------------------------------------------------------ [2022-05-29 12:44:53] odarcan at gmail dot com I dont see how tcp can send incomplete data and this is accepted as normal, I really how someone can explain or point me in the right direction, nothing is mentioned about this in the php manuals or any inclination on how do replicate or overcome such a phenomenon or that it is something common, nor that it is even something commonly known. that tcp randomly transfers less bytes goes against everything I have learned about tcp. please explain or tell me what this phenomena is called and where in literature it can even be found. if it is not a php issue or maybe a bug in some other system or the many pcs Ive tried it on that would be also acceptable thanks I am awaiting a relevant reply. ------------------------------------------------------------------------ [2021-07-29 01:22:46] requinix@php.net Please note that the term "buffer overrun" means something very different from what you meant. https://www.php.net/manual/en/function.socket-write.php > Note: > socket_write() does not necessarily write all bytes from the given buffer. > It's valid that, depending on the network buffers etc., only a certain amount > of data, even one byte, is written though your buffer is greater. You have to > watch out so you don't unintentionally forget to transmit the rest of your > data. ------------------------------------------------------------------------ [2021-07-29 00:58:35] odarcan at gmail dot com solution is this apparently socket_write causes buffer overrun when the msg is too big, so send it in chunks instead $l1=strlen($msg); $totaltransferred=0; $bsize=10000; for ($a=0;$a<$l1;$a+=$bsize){ $part=substr($msg,$a,$bsize); $l2=socket_write($msgsocket,$part,strlen($part)); $totaltransferred+=$l2; } if ($totaltransferred<$l1){ o("incomplete transfer"); } ------------------------------------------------------------------------ [2021-07-28 01:14:35] requinix@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=81304 -- Edit this bug report at https://bugs.php.net/bug.php?id=81304&edit=1

« previous php.bugs (#241619) next »