Search code examples
phpemailssllaravelswiftmailer

Laravel SSL read operation timed out | Swift_IoException | PHP bug?


I have an error in Laravel 4:

ErrorException (E_UNKNOWN) fgets(): SSL read operation timed out

156.     * @return string
157.     *
158.     * @throws Swift_IoException
159.     */
160.    public function readLine($sequence)
161.    {
162.        if (isset($this->_out) && !feof($this->_out)) {
163.            $line = fgets($this->_out);
164.            if (strlen($line) == 0) {
165.                $metas = stream_get_meta_data($this->_out);

This error refers to SendGrid. My Laravel settings are default:

laravel>app>config>mail.php

<?php

array(
  'driver' => 'smtp',
  'port' => 465,        
  'encryption' => 'ssl',
  'sendmail' => '/usr/sbin/sendmail -bs',
)

How to solve it?

(see also: Laravel.io)


Solution

  • Solution 1

    I have found a solution but it is not the best way. For testing it is ok:)

    When I uploaded my application to the cloud, I get the error. On the domain, I have turned off the SSL. In laravel>app>config>mail.php, I have changed this:

    <?php
    
    array(
      'driver' => 'smtp',
      'port' => 25, //earlier: 465     
      'encryption' => '', //earlier: 'ssl'
      //other settings
    )
    

    Solution 2

    Probably it's this bug in PHP 5.4.33 / 5.5.17 (link). You have to downgrade to version 5.4.32. Then it should work.

    yum downgrade $(rpm -qa --qf "%{NAME}\n" | grep ^php | awk '{print $1"-5.4.32"}') -y
    

    See also laravel.io.


    Solution 3

    Solution 3 is really simple, turn off all SSL on the domain.