WordPress.org

Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#2628 closed defect (bug) (fixed)

wordpress broken under apache mod_fastcgi with php ran as a cgi

Reported by: scruby Owned by:
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.0.2
Component: General Keywords:
Focuses: Cc:

Description

The error happens when php is run through fastCGI, and it is related to this problem that's reported on php bugs: http://bugs.php.net/bug.php?id=36705

To duplicate the problem, you need to compile php sapi/cli with fastcgi support, and run it under apache2/mod_fastcgi. This is what an entry in the error log looks like:

[Sat Apr 01 23:30:20 2006] [error] [client 66.215.220.80] FastCGI: comm with server "/var/www/fcgi-php/php" aborted: error parsing headers: duplicate header 'Status'

The relevant section of code is in wp-includes/functions.php

@header("Status: $header $text");
@header("HTTP/1.1 $header $text");

According to the suggestions on the php bug list, one workaround would be to rewrite this section of functions.php as follows:

if (substr(php_sapi_name(), 0, 3) == 'cgi')
@header("Status: $header $text");
else
@header("HTTP/1.1 $header $text");

I made this change myself, and it seems to make wordpress work both under mod_php and mod_fastcgi. I'm running apache 2.0.55/php 4.2.2 I've tested this code myself in both mod_cgi and mod_fastcgi configurations and it seems that all is well with it. I haven't tested this with php5, apache 1.3.x, or the extremely new apache versions above 2.0.

Attachments (1)

functions.php.diff (526 bytes) - added by leftjustified 15 years ago.

Download all attachments as: .zip

Change History (13)

#1 @scruby
16 years ago

I need to add something to this:

http://bugs.php.net/bug.php?id=36705 rears its ugly head in several places. There's no reason in the world to send a header_status(200) in classes.php function handle_404. If you send nothing, php will assume you mean 200 by default. On the other hand, if you send status_header(200), then send header("Location: . . . ") you'll end up sending an extra Status: 302 header, and fastcgi will have an internal server error again. This breaks stuff like a click on the trackback link. So, in addition to the change mentioned above, you need to take out the status_header( 200 ); from classes.php

There's no point in doing status_header(200) anyway.

#2 @ryan
16 years ago

When we didn't send the 200 people were ending up with 404s being sent instead. They were being mass de-listed from search engines.

#3 @ryan
15 years ago

  • Milestone changed from 2.0.2 to 2.0.4

#4 @leftjustified
15 years ago

  • Keywords bg|has-patch bg|needs-testing added

#5 @dje
15 years ago

I have tested this patch under Wordpress 2.0.3 PHP Version 5.0.5-3 (with fastcgi)(and Apache/1.3.34 Debian) and it solves the header issue I was having, which was exactly as described in http://wordpress.org/support/topic/67416.

#6 @hugoh
15 years ago

This patch did not work for me (using PHP5 with FastCGI). The way I solved it (which may not work for everybody) was by simply commenting '@header("Status: $header $text");' out.

#7 @foolswisdom
15 years ago

  • Keywords has-patch needs-testing added; bg|has-patch bg|needs-testing removed
  • Milestone changed from 2.0.4 to 2.2

#8 @abecciu
15 years ago

  • Milestone changed from 2.2 to 2.0
  • Version changed from 2.0.2 to 2.0

This patch works like a charm for me. It was tested on Apache 2.2.3 PHP/FastCGI 5.1.6.

#9 @foolswisdom
15 years ago

  • Milestone changed from 2.0 to 2.1
  • Version changed from 2.0 to 2.0.2

abecciu what version of WordPress are you running ? Thank you.

#10 @foolswisdom
15 years ago

  • Milestone changed from 2.1 to 2.2

#11 @markjaquith
15 years ago

[4513] and [4514] may affect this. Please test with this change applied.

#12 @foolswisdom
15 years ago

  • Keywords has-patch needs-testing removed
  • Milestone changed from 2.2 to 2.1
  • Resolution set to fixed
  • Status changed from new to closed

Closing as FIXED for now.

No response to Mark's request for testing feedback. Current work in ticket:3528 may be relevant.

Note: See TracTickets for help on using tickets.