I see that similar question has been asked several times but I don't see any answer working for me. I am trying to listen a port on my localhost with php using socket_read command and write the message to the server. The code works fine but I can only read and write only the 1st character. Say the client send "hello", socket_read
only reads the "h".
$result = socket_read ($client, 1024);
echo "Reply From Server :".$result ."
";
It almost looks like php runs so fast that as soon as socket read receives the first character the program continues to run the next line. I need socket_read to wait until the message is over or certain character is seen in the message like space or period or dollar sign or whatever.
So far I tried ;
Used the socket read in a loop so everytime a character is received I can put in an array and eventually make the word "hello". Did not work. When I use the loop I receive hundreds of null characters in seconds.
Reading PHP manual I tried to use PHP_NORMAL_READ
in the heading. When this option is used socket_read should continue until the message has or
but it does not how it works for my application.
I see that using node.js or websocket was advised but they wont work and also this is not a chat platform. All I need to have is having a php script running on my web-site and when a client sends an information I would like the php script to be able to record that message in the sql server.
Note: I have tested remote and localhost connections. There is no difference. Also there is no problem with recording the message to the server. Only problem is receiving single character with socket_read
.