This may sound unusual but I've seen it in use several times. Basically I have a program which sends smtp email. The program works great, but every now and then there will be a server that I open the socket to and it opens correctly, but then when I do a "fputs ..." something, and look for a response "fgets ...", nothing happens, and it just hangs the process.

Does anyone have a good idea on how to timeout the fgets command, or a way to work around it?

/ sending HELO command /
fputs($smtpConnection, "HELO domain.com\r\n");
$response = fgets($smtpConnection,1024);
$status = errorCheck($response);
if ($status['num'] == 1) // if the HELO command was good

By the way, I have seen some servers hang while talking to them both with sendmail and with a straight telnet into port 25, so I know it's not the code or PHP, etc.

Thanks all,
John

    I am grateful for the help. I did look at php.net first and I have also looked at the stream_set_timeout() function, but it didn't sound like what I needed. But if you say it is, I'll try it out and see what I can make of it.

    Thanks for your help.
    John

      I tried using the stream_set_timeout() and find out that my script fails with a fatal error.

      Fatal error: Call to undefined function: stream_set_timeout() in blahblah on line 213

      I am running PHP 4.2.2 and I checked my phpinfo and I did configure it with "--enable-sockets". What more do I need? The php.net site says this function is good from 4 - 4.3

      (PHP 4 >= 4.3.0)

      So shouldn't I have access to this function?

        should... I dont use sockets in PHP normally, I just searched that function out.... cant offer much more than that.... sorry

          And this: (PHP 4 >= 4.3.0)

          Should be read as:

          Function is available in PHP 4 ( ie, NOT PHP 3, or PHP 2 ) WHERE the version is greater than or equal to 4.30

            I guess I need to upgrade then. I didn't realize the proper way to read it. I presumed it was from 4 upthrough and equal to 4.3, so thanks for the education.

            John

              Write a Reply...