The following php_shell_script print's the data from stdin to stout when it's connected, instead of writing to the clients.
#!/usr/bin/php -q
<?
function sendstre($sid,$uda)
{
global $data;
if(write($sid,$data,strlen($data))<0) { echo strerror($sid); }
socket_send($sid,$data,128,0);
}
$fp=fopen("php://stdin","rb");
$sockid = socket( AF_INET , SOCK_STREAM , tcp);
$ret=bind($sockid , "192.168.2.1" ,8010);
if( !$ret == 0) {
exit;
}
if(!listen($sockid,10)==0) {exit;}
set_nonblock($sockid);
while(1==1){
if($nsock=accept_connect($sockid)>0) {
$sockacs[$nsock]=$nsock;
read($nsock,$data,10000000,PHP_NORMAL_READ);
read($nsock,$data,10000000,PHP_NORMAL_READ);
}
$data=fread($fp,128);
$sockacs=array_unique($sockacs);
array_walk($sockacs,"sendstre");
}
?>
I want it to send the data it gets from stdin to all clients that connect.
What am I doing wrong?
Marc