468,301 Members | 1,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

UNIX Socket does not send data until closed

Hi,

I am using PHP persistent sockets and have a problem with them. The
problem is that PHP only sends the data when the socket is closed. In
the code example below the counterparty process (peer) received the
connect request from PHP, but then never receives the message sent in
the "fwrite" command below - and consequently never generates the
reply which should be read by the fgets command.

Flushing the socketFP does not make any difference - the only thing
that causes the data to be sent is to fclose it (which defeats the
purpose of having persistent sockets, which I definitely need).

Any help much appreciated.

System:
PHP version 5.2.0-8+etch7, Debian Linux 2.6.18-4-486

Best regards

------------------ Code Sample -----------------------------------
$SocketFP = pfsockopen("unix:///tmp/hs.socket",0,$errno,$errstr);
if ($SocketFP == FALSE) {
... error handling
}

stream_set_timeout($SocketFP,2);
stream_set_blocking($SocketFP,1);
$Msg = sprintf("ConnectId %d\n\r",$OurId);
$i =fwrite($SocketFP,$Msg);
fflush($SocketFP);

if ($i==FALSE) {
... error handling
}

$message = fgets($SocketFP);

Jul 24 '07 #1
1 2586
C.
On 24 Jul, 17:35, Chris <dr_christopher_hega...@hotmail.comwrote:
Hi,

I am using PHP persistent sockets and have a problem with them. The
problem is that PHP only sends the data when the socket is closed. In
the code example below the counterparty process (peer) received the
connect request from PHP, but then never receives the message sent in
the "fwrite" command below - and consequently never generates the
reply which should be read by the fgets command.

Flushing the socketFP does not make any difference - the only thing
that causes the data to be sent is to fclose it (which defeats the
purpose of having persistent sockets, which I definitely need).
------------------ Code Sample -----------------------------------
$SocketFP = pfsockopen("unix:///tmp/hs.socket",0,$errno,$errstr);
if ($SocketFP == FALSE) {
... error handling
}

stream_set_timeout($SocketFP,2);
stream_set_blocking($SocketFP,1);
$Msg = sprintf("ConnectId %d\n\r",$OurId);
$i =fwrite($SocketFP,$Msg);
fflush($SocketFP);

if ($i==FALSE) {
... error handling
}

$message = fgets($SocketFP);
stream_set_blocking($SocketFP,1);
- doesn't it open the socket in blocking mode anyway? (not sure how
much sense fflush() would make if it were non-blocking).

I suspect its not relevant, though ISR something about newlines and
flushes on streams - but your script above does have a newline char -
but normally where a line is terminated by a CR and LF, the CR comes
first. This may be a problem - I'd try with a different client but
don't know of a generic tool for Unix domain sockets - nc will work
for a TCP socket though.

I'd also suggest checking the value of $i and what fflush() returned.

HTH

C.

Jul 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Terry | last post: by
13 posts views Thread by coloradowebdev | last post: by
reply views Thread by Holly | last post: by
4 posts views Thread by Adam Clauss | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.