$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
socket_connect($socket, CLAMD_SOCKET);
socket_send($socket, 'PING', 4, 0);
socket_recv($socket, $output, 4, 0);
// check to see if $output === PONG (which it is)
$scan = 'SCAN ' . $file;
socket_send($socket, $scan, strlen($scan), 0);
socket_recv($socket, $output, 100, 0);
// $output should contain the result from the socket, but instead it's blank
// var_dump says it's a 1 character string " "
This is my original code.
However, if I close the socket after the PING command and PONG is returned (which it is), then re-open it again, the SCAN command works and it returns the result as expected.
Is this how it's supposed to work, or do I need to do something else in between the commands? Is the socket not ready for another command to be sent?
I'm not really sure what to look for, I can't find anything in the PHP manual. It does work, but I feel as if having to close the socket and re-open it is the wrong way to do things.