Skip to content
Advertisement

“End of script output before headers” in Apache + PHP

UPDATE: This issue was caused by the server request timing out before the script completed.*

I have legacy code running on a shared LAMP host (nearlyfreespeech.net), and I recently added a new script that refuses to work in production.

My apache error logs show the message End of script output before headers: switch.php, and I get 500 statuses when trying to trigger the script with a web client.

According to other StackOverflow posts, this error message is usually due to a file permissions error. However, the file permissions on the new script are the same as all the others.

Here are the relevant file permissions:

-rw-rw-r--   1 235430  235430  1655 Jul  6 18:05 switch.php

drwxrwxr-x   2 235430  235430    18 Jul  1 21:05 auth/
-rw-rw-r--  1 235430  235430     13 Aug 24  2015 auth/.htaccess
-rw-rw-r--  1 235430  235430    280 Jul  1 21:05 auth/cloudsaves.2.php
-rw-rw-r--  1 235430  235430    880 Aug 28  2015 auth/cloudsaves.php
-rw-r--r--  1 235430  web     15580 Jul  1 21:05 auth/rumpus_migration.php

With these include() heirarchies:

  • switch.php -> auth/cloudsaves.php (works)
  • switch.php -> auth/cloudsaves.2.php <- auth/rumpus_migration.php (does not work)

All requests are for switch.php and include a parameter value causing either auth/cloudsaves.php or auth/cloudsaves.2.php to be included.

In my local test environment everything works just fine. In production when I use the parameter that causes switch.php to include the cloudsaves.2.php script I get the error.

I’ve tried changing the group and permissions on rumpus_migration.php and cloudsaves.2.php to exactly match other files that are properly being included by the parent switch.php script, always with the same outcome. This new script (cloudsaves.2.php) is the only script included by switch.php that itself includes another script.

I’m not familiar with Apache or PHP, and the production code is on a shared host where I have extremely limited admin access. The fact that the code works locally but not in production makes it seem that a permissions issue is a likely culprit, but I don’t know how to move forward since none of the working permissions options seem to fix it.

Advertisement

Answer

The issue was that the request was timing out before the script completed, due to a long-running database query.

So that generic End of script output before headers error can be caused by server timeouts as well as file permissions issues.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement