Browser says 'error on line 1 at column 1: Document is empty' for a PHP XML page
This page contains the following errors: error on line 1 at column 1: Document is emptyShort answer
This browser message means the PHP script returned no output at all, so there is no XML to parse. Almost always PHP stopped on an error it did not print: a fatal error with display_errors off, or a parse error in the file itself. Read the PHP error log, not the browser.
Fix it fast
1Find out which cause you have
Request the URL with curl and look at the body and the status code. An empty body with 500 points to a PHP error.
curl -i https://example.com/feed.php2Match what you see, then jump to its fix
- 1
curl returns status 500 with an empty bodyA fatal error happened and display_errors is OffFix - 2
Setting error_reporting or display_errors at the top of the script changes nothingThe file has a parse errorFix - 3
simplexml_load_string() gives false and the page ends emptyYour own code reads XML and fails with no detailFix
- 1
What does the error look like?
This page contains the following errors: error on line 1 at column 1: Document is emptyBelow is a rendering of the page up to the first error.
Cause 1 of 3
A fatal error happened and display_errors is Off
1Check
display_errors is On by default, but php.ini-production sets it to Off, so errors are not printed and the response is empty. The advice for production is to log errors instead.
php -i | grep -E "display_errors|log_errors|error_log"2Fix
Turn logging on, read the log, and fix the error it names. Show errors on a development copy only.
; php.ini
log_errors = On
error_log = /var/log/php/error.log3Verify
Request the URL again and read the last lines of the log.
tail -n 20 /var/log/php/error.logConfirmed by php.net
Cause 2 of 3
The file has a parse error
1Check
PHP parses the whole file before it runs any of it. A missing bracket or semicolon produces a blank page, and ini_set at the top of that same file never runs.
tail -n 5 /var/log/php/error.log2Fix
Enable error display in php.ini on the development copy, or include the risky file from a small wrapper that sets display_errors first.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'feed-real.php';3Verify
Load the wrapper: the parse error now prints on the page.
curl -i https://example.com/feed.phpConfirmed by php.net
Cause 3 of 3
Your own code reads XML and fails with no detail
1Check
The function raises an E_WARNING for each XML error and returns false on failure. Collect the errors to see line and column.
grep -R -n "simplexml_load" --include=*.php .2Fix
Turn on libxml internal errors, test the result with ===, and print the collected messages to the log.
libxml_use_internal_errors(true);
$xml = simplexml_load_string($data);
if ($xml === false) {
foreach (libxml_get_errors() as $e) {
error_log(trim($e->message) . ' line ' . $e->line);
}
}3Verify
Run the request again and read the log.
tail -n 20 /var/log/php/error.logConfirmed by php.net
How do I stop it coming back?
- Keep log_errors on in production and read the log after each deploy.
- Run the feed URL through curl in your deploy checks and test for a non-empty body.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix