I am connecting to a remote website via sockets. I am expecting a specific string 'XXX' from the remote site. Upon receipt of the string, I want to send back an 'ACK' 200 OK response back to the remote server.
This is what I have so far (assume socket successfully opened); $fp is resource (pointer) to the socket:
while (!feof($fp)) {
$data = fgets ($fp, 1024);
if (strcmp("PASS",$data)==0) {
// Send 200 OK 'ack' response to remote server
$response = "HTTP/1.0 200 OK\r\n";
fputs ($fp, $response);
// Do additional processing here ...
}
}
fclose($fp)
What I am not sure about, is whether it is 'legal' to use fputs in the (!feof()) while loop. If there is anything wrong with the above code, I will be grateful if someone could point it out (i.e. if it could be written better).