Im trying to understand how a socket works in PHP.
Lets say I have a file called socket.php, and this creates a socket bound to my localhost on port 99. 
Then I run the socket in a while loop so it's constantly connected.
is there a function in PHP to make calls to that socket while its listening?
Another question is: If I have another service such as Java running on a socket -- is it a bad idea to use PHP to connect to the socket to make a call. I ask because I could potentially be recreating new socket connections many, many times.
So is having to reconnect to a socket hundreds of times in PHP bad? Or should I re-use the same socket connection somehow? (I am thinking in terms of AJAX calls to PHP which connects to a Java Socket).
Edit: You can see the example code: https://github.com/JREAM/sandbox/tree/master/php
Im trying to communicate with in socket.php and socket_send.php -- I am leaving socket.php running and opening another console and running socket_send.php and trying to get a result into the console.
function cmd($str, $report=true){ //Assume connection to socket connection on $fp (File Stream Pointer) //Echo command, format it for socket, and write to stream global $fp; echo htmlspecialchars("> ".$str); echo "\n"; $ret = fwrite($fp, $str."\r\n"); if($report === true){ echo htmlspecialchars(fread($fp, 512)); echo "\n"; } /*else { fclose($fp); echo "</pre>\n"; die("<b>ERROR:</b> Unable to write content to File Pointer Stream.\n"); }*/ }socket_read(). Where do$reador$clientget assigned any array data?