|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68432 socket_read
Submitted: 2014-11-17 03:57 UTC Modified: 2014-11-18 08:24 UTC
From: cheeto_crunch at yahoo dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.6Git-2014-11-17 (Git) OS: Debian / Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cheeto_crunch at yahoo dot com
New email:
PHP Version: OS:


 [2014-11-17 03:57 UTC] cheeto_crunch at yahoo dot com
According to the PHP documentation,, the type PHP_NORMAL_READ - reading stops at \n or \r. It is supposed to stop that read function after a \n or \r but it does not.

How to duplicate: Create a client and a server, both in php. From the server, send multiple fast consecutive socket_write functions to the client. The client will read them all as one packet instead of separating them based on the \n or \r of the packet received.

Test script:
Will be pulling my code apart to recreate the bug. This will take some time as I will not be providing my entire code. (It would greatly complicate the issue).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-17 04:14 UTC]
-Status: Open +Status: Feedback
 [2014-11-17 04:14 UTC]
Not much to do until we can see that code. Reopen this when you have it ready.
 [2014-11-17 05:08 UTC] cheeto_crunch at yahoo dot com
-Status: Feedback +Status: Open
 [2014-11-17 05:08 UTC] cheeto_crunch at yahoo dot com
The source code that duplicates this error can be found here:

Result from client side:
cserver@dns:~/bug/client$ php client.php
DEBUG: hubConnect: Connecting to
DEBUG: hubConnect: Connect success. (Resource id #7)
DEBUG: socket_recv: 1. test1
2. test1
3. test1
4. test1
5. test1
6. test1
7. test1
8. test1
9. test1
10. test1

DEBUG: socket_recv: 1. test2

DEBUG: socket_recv: 2. test2

DEBUG: socket_recv: 3. test2

DEBUG: socket_recv: 4. test2

DEBUG: socket_recv: 5. test2
 [2014-11-17 05:22 UTC]
-Status: Open +Status: Feedback
 [2014-11-17 05:22 UTC]
That code never even reaches the call to socket_read(); verify that with
  $buf = socket_read($hub, 4096, PHP_NORMAL_READ);
  doDebug("socket_read: $buf");
in client.php.

The fact that socket_recv() returns all the values at once is a race condition - on my Windows machine I get one at a time, but if I sleep(1) after the hubConnect() then I get the same results as you. (It also doesn't do the PHP_NORMAL_READ thing, of course.)

Now, if I keep the sleep(1) and new doDebug, and remove the while loop on socket_recv(), socket_read() kicks in and gives one value at a time.

Can you revise the repro code, or does what I just said explain away your problem?
 [2014-11-18 07:44 UTC] cheeto_crunch at yahoo dot com
-Status: Feedback +Status: Open
 [2014-11-18 07:44 UTC] cheeto_crunch at yahoo dot com
I believe you're correct. It seems to only reach the sock_read part of the code on disconnect. I appear to be incorrect about a bug existing, though this issue has created a fun problem for me to solve, lol.

Thank you for your time. My apologies for the error on my behalf.
 [2014-11-18 08:24 UTC]
-Status: Open +Status: Not a bug
 [2014-11-18 08:24 UTC]
Not a problem.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 21:03:35 2022 UTC