Why are you always reading byte by byte from the socket? $len is always 1.
If you receive multiple data sets, then you might need to cache the leftovers from the previous read.
I did this also once when starting with sockets and saw then the huge speed improvement.
One issue is that on multiple platforms different read sizes are recommend, but I would recommend you to use a len of at least 1024.