Voting

: max(six, seven)?
(Example: nine)

The Note You're Voting On

dhaubert dot ti at gmail dot com
9 years ago
A way to wait for a message response by the socket or take the first message incoming.

Note that if the server turn offline, you have a socket resource, but while trying socket_read(), it gives you a warning message that will fill your hard drive kickly due to logging.

The example above try read the message at best 3 times, 3 seconds sleeping for another reading.
<?php
function waitResponse($response = "") {
$status = "";
$tries = 3;
$counter = 0;
while (
$status == $response) {
$status = socket_read($socket, 1024);
if(!
$status){
if(
$counter >= $tries){
break;
}else{
$counter++;
sleep(3);
}
}
}
return
$response;
}

<< Back to user notes page

To Top