1
[Sat Apr 25 04:18:46.660552 2015] [fastcgi:error] [pid 11271:tid 140464355243776] [client 95.87.236.146:63037] FastCGI: comm with server "/usr/lib/cgi-bin/php5-fcgi-domain.cc" aborted: idle timeout (30 sec), referer: http://domain.cc/login/restore_session.php?redirect=yes
[Sat Apr 25 04:18:46.660673 2015] [fastcgi:error] [pid 11271:tid 140464355243776] [client 95.87.236.146:63037] FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi-domain.cc", referer: http://domain.cc/login/restore_session.php?redirect=yes

I am getting these errors in my error.log file. This happens when I try to send an email with the mail() function:

$to = $ticket->email;
$subject = "X Support";
$message = "We have just answered your support ticket! Here is our message: \n\n-------------\n\n" . $text . "\n\n-------------\n\nIf you wish to reply, please visit http://domain.cc/support.php";
$headers = "From: [email protected]\r\n" .
"Reply-To: [email protected]\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$result = mail($to, $subject, $message, $headers);

I'm calling this code with AJAX and as a result when I click "Send Reply", the page just hangs and I get 500 error as a response after 30 seconds. The weird thing is that this code used to work fine for a few months.

EDIT: I forgot to mention - the emails get delivered anyway.

4
  • You're missing the \r\n after phpversion(). But I don't think that should cause an error, it just won't do the CC.
    – Barmar
    Commented Apr 25, 2015 at 8:29
  • Like I said, I didn't expect that to fix it.
    – Barmar
    Commented Apr 25, 2015 at 8:31
  • Note that the log message isn't referring to the mail headers, it's talking about the HTTP headers that should be sent from PHP to Apache.
    – Barmar
    Commented Apr 25, 2015 at 8:32
  • I suspect there's a problem with the mail configuration on your server.
    – Barmar
    Commented Apr 25, 2015 at 8:33

2 Answers 2

1

In your setting, the connection between Apache and PHP is done with a variant of CGI, fastcgi. That's why you're seeing fastcgi:error in your logs. When Apache receives a request for an URL that's a PHP file, say "my-site.tld/index.php", it passes the request along to PHP. Then PHP "does it's thing" and sends back its output. That PHP output then gets send out by Apache to the client who did the request.

But Apache doesn't wait forever for PHP to answer. There's an "idle timeout" of 30 seconds. After that's gone by, Apache assumes that PHP won't be sending an answer anymore. That's what's happening in your case, as you can see in comm with server "/usr/lib/cgi-bin/php5-fcgi-domain.cc" aborted: idle timeout (30 sec). So Apache doesn't have anything to send back to the client who did the request, not even (complete) headers, because it received only 0 bytes from PHP: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi-domain.cc"

The conclusion is: For some reason, the execution of your code takes PHP longer than the timeout of 30 seconds. That triggers Apache to think "I've waited long enough, there won't be an answer". The next question you should look into IMHO, what makes your PHP code take so long.

One possible approach would be to remove/comment out parts of the code and see if the rest gets executed within the 30 seconds limit. Does it still break the timeout limit when you only do $to = $ticket->email;? Next step, does it still break the limit when you only do the first two lines and so forth. If that's the most feasable approach depends on the details of your setting and work environment.

2
  • If I end the script just before the mail() function it doesn't hang. Commented Apr 25, 2015 at 10:05
  • So it looks like the mail server (MTA, mail transport agent, in current settings with some probability Postfix) that accepts the mails from PHP and sends them out is delaying things. You may need to talk to the MTA's admin/postmaster and/or look into the MTA's logs for further clues. Which MTA PHP's mail() function uses is set in php.ini, look for directives like SMTP or smtp_port. Commented Apr 25, 2015 at 10:17
0
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'To: Segreteria <[email protected]>' . "\r\n";
    $headers .= 'From: Gestore corrispondenza ZENITH <[email protected]>' . "\r\n";

These are my headers for the mail function and they are working well with different smarthosts. Can you try with these and see if you get any further error?

8
  • Still the same. I just replaced "Segreteria <[email protected]>" with '.$to.' Commented Apr 25, 2015 at 8:35
  • You have to replace also the From address. Btw is the smarthost up and running? Can you ping it? Can you try to send a mail from the command line? What kind of smarthost are you using? Commented Apr 25, 2015 at 8:37
  • I'm running an Ubuntu server on DigitalOcean. What do you mean to ping it? Like "ping <server ip>" from terminal? Commented Apr 25, 2015 at 8:39
  • Yes. Is your Ubuntu machine sending mail directly or via a SMTP server? Commented Apr 25, 2015 at 8:40
  • I believe it's Ubuntu who sends the emails, but not sure. How to check that? Commented Apr 25, 2015 at 8:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.