Hi,
I have a PHP-client who talks with a Perl-server through a AF_UNIX socket. The socket works ok in the PHP->Perl direction, but the other way doesn't work. The PHP-client just blocks in the 'fgets'-command. I have tried to flush the socket in the Perl server but the information never arrives to the PHP-client. (That's almost true. The information arrives if I send at least 820 byte from the server). Suggestions?
PHP-client:
$sock = fsockopen("/tmp/HstSrv", 0);
if(!$sock) die("ERROR Could not connect to server.\n");
while(1) {
$cmd = fgets($sock);
if (!$cmd) die ("closed conn\n");
echo "Recieved package: ".$cmd."\n";
}
Perl-server:
use Socket;
use Carp;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
my $NAME = '/tmp/HstSrv';
my $uaddr = sockaddr_un($NAME);
my $proto = getprotobyname('tcp');
socket(Server,AF_UNIX,SOCK_STREAM,0) || die "socket: $!";
unlink($NAME);
bind (Server, $uaddr) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";
my $waitedpid;
sub REAPER {
$waitedpid = wait;
$SIG{CHLD} = \&REAPER; # loathe sysV
}
$SIG{CHLD} = \&REAPER;
for ($waitedpid = 0; accept(Client,Server) || $waitedpid; $waitedpid = 0, close Client)
{
select Client;
$| = 1;
while(1) {
my $input = <STDIN>;
chop $input;
print $input."\015\012";
$| = 1;
}
}