Ethernet Shield TCP Socket & PHP fsockopen

I'm experiencing a problem interfacing Arduino Ethernet Shield TCP Sockets with PHP Socket handler.

From PHP (Web Server: APACHE) I open a socket (fsockopen) to the Arduino...it opens and then I put a command (fwrite) that Arduino should answer. Arduino infact send the answer that I read from PHP (fread).

This kind of communication is not stable: - there are times that after the first connection (and disconnection at the end) PHP is not able to reconnect to Arduino (that works...I can connect to Arduino for example with telnet) - there are times that PHP can't receive the stream...it sends, but not receive

I think that this two cases are related...beacuse it seems that when PHP try to retrieve data from socket...it hangs...

Sorry if my English isn't perfect...I hope it is understandable!!!

Sorry if my English isn't perfect.

The code is the same in any language. Post some.

PHP Code

$fp = fsockopen("192.168.0.177", 6301, $errno, $errstr, 10);
fwrite($fp, "\n\r");
while (!feof($fp)) {
    echo fread($fp, 128);
}
fclose($fp);

It opens the socket, write a new blank line and waits for results...

I don't have the Arduino code now, but it simply create a tcp server that listens on 6301 port, when it receive a new blank line, it write some data to the sockets. I think, but I could be wrong, that the Arduino code is not necessary beacuse it works fine if I open the socket with TELNET or with an HTTP Browser (such as Chrome)...so it works...the problem isn't in the Arduino code! However I don't have the code now! :)

Thank you in advice! :)

Does it make any difference, in terms of used amount of RAM, speed and stability, using the Websockets instead of HTTP?