5

My log is cluttered with this message:

Warning: Cannot modify header information - headers already sent by (output started at /home/path/to/drupal/7/includes/common.inc:2681) in drupal_send_headers() (line 1216 of /home/path/to/drupal/7/includes/bootstrap.inc).

It occurrs only when someone types address to a non-existing comment like this:

http://example.com/comment/874

If the comment exists, or for any other address, there is no error. (I was deleting lots of spam comments recently and the bots keep coming back to read their own comments, that's why there is a lot of not found comments.)

Is there any means to get rid of this error? The only comment module I have is Comment Goodness and there isn't complaint on such error in the issue queue, so maybe it's something else. I checked all my custom module files and each of them starts with <?php and there is no space or anything before this tag, and there is no closing tag. I have no idea what else to check.

  • I've seen a lot of these warnings recently too, on a few different sites. Only on 404 pages though (not just comment pages). I haven't got round to debugging it yet, would be interested to see if it's a wider problem – Clive Jun 11 '13 at 21:44
  • I would also check all the custom modules and theme files that if the php ending ?> at the end of the file is omitted. This is a best practice recommended on Drupal Coding Standarts. https://drupal.org/coding-standards#phptags – Елин Й. Jun 11 '13 at 21:52
  • 1
    This is an old PHP gotcha. If in your preprocessing you place a closing tag and then a space, you have created page output and headers are sent. The best practice used to be to omit the closing tags from php files so an accidental space would not trigger the problem. – Triskelion Jun 11 '13 at 21:54
  • @Triskelion In my case I have no closing PHP tags in any file. They're probably unrelated to be honest, I'm seeing it for all 404 pages on a couple of sites (with very little in common) – Clive Jun 11 '13 at 21:58
  • 1
    @Triskelion Not on my watch ;) – Clive Jun 11 '13 at 23:13
6

In my own case, I've found that this was due to modules that attempt to return a 404 by mistakenly calling drupal_not_found() instead of returning the MENU_NOT_FOUND constant. This causes drupal_deliver_page() to be called twice in a single page request.

Views is the biggest culprit right now; see https://drupal.org/node/1414068 (comment #16) for a patch that resolves it. You should grep through your modules directory for "drupal_not_found" to find other modules with this problem.

| improve this answer | |
3

I have seen a few things cause this.

A closing ?> on a file with space after it. The Drupal convention is to not use the closing PHp tag on any file.

A UTF-8 encoded file with a BOM. The BOM would be before the the opening <?php, and is output.

Following the advice of Yahoo! YSlow and adding a flush() between the </head> and <body> in html.tpl.php

Debug directly using print or print_r instead of dsm() in code.

I also recall a weird problem I had where I had some framebusting code in a template file, and if a linked resource 404ed, then I think I had this problem b/c the Drupal 404 page would load for the linked resource.

| improve this answer | |
0

Building on Les Lim's answer, combined with your finding that you are seeing this with comment URLs, you are probably seeing issue #2218501 from the Comment Goodness module (are you using that on your site?). It is inserting its own callback for comment URLs and is indeed calling drupal_not_found() when it can not find the comment (where it should be retuning MENU_NOT_FOUND).

There is a patch in the issue, and it has been committed to the development branch of the module, in october of 2014. Looking from the project status and the issue queue, it doesn't look like we can expect an updated official release any time soon, though.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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