PHP Classes

php (socket) can't write data without break or exit

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  php (socket) can't write data...  
Subject:php (socket) can't write data...
Summary:php socket
Date:2020-04-07 03:07:57
Update:2020-04-07 03:37:36

  1. php (socket) can't write data...   Reply   Report abuse  
Picture of bala bala - 2020-04-07 03:37:36
This is my code to connect java socket:-


$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_connect($socket, '', 12345);



// read a line from the socket

$line = socket_read($socket, 1024, PHP_NORMAL_READ);


$someArray = json_decode($line, true);

$otp = $someArray["otp"];

if($someArray["msg"] == "otp_generation")


$myObj = new \stdClass();


$send = json_encode($myObj);

socket_send($socket, $send, strlen($send), 0);





When connection is established successfully server send one OTP to client and received successfully in client. Then i send data to server OTP RECEIVED acknowledgement, it also received in server. After OTP RECEIVED acknowledgement server send welcome msg to client. I cant get the welcome message. if i remove the (exit) soket_write is not working i can't send data to server. if i put exit data send to server successfully and socket is closed. What can i do for this type of issue.

I don't know what mistake i done.?

I cant share my java server code. i create php server and client.
Here i attach the files.

Server -
Client -