I'm new to the forum and I take this opportunity to say hello at everyone. I'm not an expert on php, but even a neophyte. That being said let's move to the problem, as mentioned in the title concerns the socket. Before putting the parts of the code that interest me start by saying that if to be sent through the socket is a simple sentence and not an array everything is working correctly, then the problem occurs only with an array. 1) client.php:
$array = array('Say' => 'hello');
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
socket_connect($socket, $host, $port);
socket_write($socket, $array, strlen($array));
$result = socket_read ($socket, 1024);
2)server.php:
$output = array();
while(1){
$spawn = socket_accept($socket);
$input = socket_read($spawn, 1024);
array_push($output, $input);
socket_write($spawn, $output, strlen ($output));
}
Personally I think there is more than one error, first I would say that for example $ input is not an array, but it must contain a value that is an array, then would start already from here, also do not know if it is possible to send an array using sockets. And 'possible or do I have to split the array and I have to send the data twice?
Translate from google, sorry for bad english.
Bye!!