Search code examples
phplaravel-4fgetsswiftmailer

fgets() halting without error in Swiftmailer


I'm attempting to generate a test email in Laravel 4.2 (Windows 7, IIS 6.1), and I've encountered a silent termination - it just fails, doesn't return my view, and doesn't return an error or Exception. I've managed to brute force my way through the Laravel codebase and located the termination within Swift\Transport\AbstractSmtpTransport::_getFullResponse(), specifically the line $line = $this->_buffer->readLine($seq);:

protected function _getFullResponse($seq)
{
    $response = '';
    try {
        do {
            $line = $this->_buffer->readLine($seq);
            $response .= $line;
        } while (null !== $line && false !== $line && ' ' != $line{3});
    } catch (Swift_IoException $e) {
        $this->_throwException(
            new Swift_TransportException(
                $e->getMessage())
            );
    } catch (Swift_TransportException $e) {
        $this->_throwException($e);
    }

    return $response;
}

That do loop executes twice. The first time $line is assigned the value * OK The Microsoft Exchange IMAP4 service is ready., which is great, as obviously I'm getting to the server. Unfortunately, the second iteration fails in Swift\Transport\StreamBuffer::readLine() at the line $line = fgets($this->_out); :

public function readLine($sequence)
{
    if (isset($this->_out) && !feof($this->_out)) {
        $line = fgets($this->_out);
        if (strlen($line)==0) {
            $metas = stream_get_meta_data($this->_out);
            if ($metas['timed_out']) {
                throw new Swift_IoException(
                    'Connection to ' .
                        $this->_getReadConnectionDescription() .
                    ' Timed Out'
                );
            }
        }

        return $line;
    }
}

I've tried wrapping that line in a try/catch, and nothing happens, the code just halts with no information on the second iteration of the do loop. So, any advice as to a) how to squeeze more information out of the halt or b) what could cause fgets() to halt this way?


Solution

  • Ok, progress: after broadening my search to Swiftmailer in general, I was able to find mention of a timeout occurring at that particular line in Swiftmailer. By extending the max_execution_time in php.ini I was able to get an actual Exception:

    Expected response code 220 but got code "", with message "* OK The Microsoft Exchange IMAP4 service is ready. * BYE Connection is closed. 13 "

    I think under the circumstances I'll close this question and move onto figuring out why I'm not getting a 220.