1

I'm experimenting with a very simple php server. It accepts one connection, reads what's sent, writes it and exits (I'm running it from the cli). The code is what follows. The problem is that whenever the length of the data exceeds 1024, it doesn't intercepts the end of data and so it just hangs. Any help? Thanks

$out= '';
while ($out = socket_read($client, 1024))
{
 echo $out; 
}

echo "ok";

socket_close($client);
socket_close($sock);

?>

2 Answers 2

4

Because your last socket_read will be hang on waiting for another data, why?

Because you while is never ending. socket_read function return data, data will be always, if will be not socket_read will be waiting for new data to result.

Use socket_select function to check data existence before you call socket_read then you will protect from the function hanging and in this moment you can end.

Sign up to request clarification or add additional context in comments.

Comments

0

example ... Use socket_select function to check data existence before you call socket_read then you will protect from the function hanging and in this moment you can end.

please...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.