<?php
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
if (socket_connect($sock, '127.0.0.1', 10000) === false) {
echo "socket_connect() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
$msg = "test";
socket_write($sock, $msg, strlen($msg));
if (false === ($buf = socket_read($sock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
echo "response: $buf \n";
I am using this code to connect to a C socket server. Server is functioning without any problems with clients that are written by C. But when I use php client it hangs after 2 attempts at socket_read. First two results are good but after that it hangs at socket_read. What might be the main cause of this behavior I have no idea.
Any suggestions ?