473,216 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

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 2931
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Terry | last post by:
It's my understanding of UDP sockets that if there is a thread blocked on a "recvFrom()" call and other thread sends a UDP packet to some address, that if the machine on the other end isn't up,...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
2
by: yvan | last post by:
Hi, Here is my client/server scenario: Step1: Client connects to server and sends data sucessfully (using Socket.Send()). Step2: Server gracefully exists (calls Socket.Shutdown() and...
5
by: Kurt | last post by:
I have a client & server app which communicates using the socket class. If I shutdown the server closing the socket the client still thinks the socket is open. Even calling send does not throw an...
0
by: Holly | last post by:
I copied this code that works to connect into Unix. I am looking for a way to get it to work with a secure Unix box. Anyone have any insights on how to do this? I am trying to build an sftp...
4
by: Adam Clauss | last post by:
A while back I posted regarding a problem we were having with one of our applications which was randomly crashing. Monitoring memory usage revealed a spike in nonpaged pool memory just prior to...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.