The ERR_INVALID_RESPONSE error occurs when a web server does not return a valid HTTP response to a client (e.g., browser, API request). This typically happens when:
The error usually comes from:
To fix it, follow these troubleshooting steps.
First, check if the PHP script has errors. Add this to the top of your PHP file:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
Run the script through the command line:
php -l your_script.php
Use this at the top of your script to force proper headers:
<?php
header("Content-Type: text/html; charset=UTF-8");
header("HTTP/1.1 200 OK");
?>
Make sure no whitespace or unexpected output appears before header() calls.
Incorrect:
echo "Hello";
header("Content-Type: application/json");
Correct:
header("Content-Type: application/json");
echo json_encode(["message" => "Success"]);
The web server might not be handling PHP requests correctly.
sudo nano /etc/apache2/apache2.conf
<IfModule mod_php.c>
AddType application/x-httpd-php .php
</IfModule>
sudo systemctl restart apache2
sudo nano /etc/nginx/sites-available/default
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
sudo systemctl restart nginx php8.0-fpm
If the browser is not showing a detailed error, use curl:
curl -I http://yourdomain.com/script.php
| Response | Meaning |
|---|---|
200 OK |
Server is responding correctly |
500 Internal Server Error |
PHP error (check logs) |
403 Forbidden |
Permissions issue (check file ownership) |
404 Not Found |
Incorrect script path |
Sometimes, corrupt sessions or cookies can cause ERR_INVALID_RESPONSE.
Delete old session files:
rm -rf /var/lib/php/sessions/*
Some security modules (ModSecurity, Fail2Ban, Cloudflare WAF) may block PHP responses.
sudo tail -f /var/log/apache2/modsec_audit.log
sudo fail2ban-client status apache-php
sudo fail2ban-client unban <IP>
| Step | Solution |
|---|---|
| 1 | Enable PHP error reporting and check for syntax errors |
| 2 | Ensure correct headers are sent (header("Content-Type: text/html")) |
| 3 | Check Apache/Nginx configuration for proper PHP handling |
| 4 | Use curl to inspect HTTP response codes |
| 5 | Clear PHP sessions and browser cookies |
| 6 | Check ModSecurity or firewall blocking requests |
By following these steps, you can identify and fix ERR_INVALID_RESPONSE in PHP quickly and efficiently.
If the issue persists, check server logs (/var/log/apache2/error.log or /var/log/nginx/error.log) for additional details.