I have a perl program running on a unix box that opens a socket. My PHP sends a command/args to the socket using fsockopen.

Perl receives the command/args, does what it needs to do and returns a string.

Back at the PHP end I'm using fgets to read the data back.

However, all I get is an error stating that the command took longer than 30 seconds and quits.

Does anyone have any ideas. Below is the bit of PHP that I'm using.

$fs = fsockopen($server, $port, $errno, $errdesc, 10);
if (! $fs) {
die("Could not connect to server/host:\nError: $errno = $errdesc\n");
}
$page = '';
fputs($fs, "getdirlist=$path");
while($line = fgets($fs, 1024)) {
$page .= $line;
}
echo $page;

    in your fsockopen function you've set the timeout to 10 seconds, so the fact that you are being told it is timing out in 30 shows that the error is in your script, not in the socket call.

    it might be that you're not closing the connection, with fclose...

    adam

      Thanks for replying Adam.

      You were right - I had omitted an fclose.

      I modified the script to remove the while/fgets loop and added an fclose as well.

      As soon as I removed the while/fgets loop - the PHP responds instantly - although I don't read any data back from the Perl socket call of course!

      So I'm stuck where I was before: the call to Perl works, Perl responds, and as long as I don't try to read from the socket PHP doesn't hang. I just can't see why this is so difficult.

      Maybe Perl isn't sending it back so PHP never has anything to read???

      I wonder if blocking has anything to do with it?

        Write a Reply...