$rin = ''; vec($rin,fileno($sd),1) = 1; $nfound = select($rin, undef, undef, 1.0); if ($nfound) { if ($line = <$sd>) { ... } else { ... knows other side closed the socket ... } }