I have a netcat server, running from command line:
netcat -l -q0 -p 9999 -c "tesseract stdin stdout -l spa"
I can connect to this server using netcat client:
cat /tmp/autogenerado.jpg | netcat 127.0.0.1 9999
So, I send a jpeg file to another server, and receive the OCR'ed data in client.
I want to do this in PHP:
$fp = fsockopen("tcp://127.0.0.1:9999", $errno, $errstr);
if (!$fp) {
echo "{$errno}: {$errstr}\n";
die();
}
fwrite($fp, $jpeg);
$contents = stream_get_contents($fp);
fclose($fp);
return $contents;
But the script hangs on stream_get_contents
. I think it is because the netcat server doesn't know when the PHP client has finished sending data.
Is it possible to send an EOF ?