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

From: Date: Mon, 30 May 2022 07:26:38 +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-241620@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 User updated by: odarcan at gmail dot com 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: 1. Have you tried my code? 2. Do you know how to change it to make it transfer the exact correct amount every time? 3. Do you find it peculiar that none of the pages for socket functions in php manual neither MENTION nor SHOW anything about additional precautions in order to make tcp transfer exact and correct amounts every time? Do you assume that it "should be working" and therefore need no additional explanation? if you cant provide me with a correct solution on how to transfer 15 mb of data in php, via socket create, bind, listen, accept, read and write, I request that you reopen this ticket as a bug. If you can, Id want to learn why it has not been mentioned in the manuals nor on the web. I have done my share of programming with udp, tcp blocking and non blocking. TCP is supposed to do complete transfers regardless of some sleep delay being added. Broken connections almost every single time is not the norm for this. Previous Comments: ------------------------------------------------------------------------ [2022-05-29 20:34:43] requinix@php.net 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 ------------------------------------------------------------------------ [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"); } ------------------------------------------------------------------------ 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 (#241620) next »