Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Chrome shows net::ERR_INCOMPLETE_CHUNKED_ENCODING on a PHP page

Errornet::ERR_INCOMPLETE_CHUNKED_ENCODING

Short answer

The browser got a chunked response that ended before its final zero-length chunk, so the connection closed mid-page. With PHP the usual reasons are a read timeout in the web server or the script being stopped by PHP or PHP-FPM before it finished. Find the timeout that matches how long the failing request ran, and raise it or shorten the work.

  • Applies to Chrome, nginx 1.26, PHP-FPM 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Time the failing request and read the web server error log at the same moment. A failure after a round number of seconds (30, 60) points straight at a timeout.

    time curl -sS -o /dev/null -w '%{http_code} %{size_download}\n' https://example.com/slow-report.php
    sudo tail -n 20 /var/log/nginx/error.log
  2. 2Match what you see, then jump to its fix

    1. 1The request fails after about 60 seconds, and the nginx error log mentions a timeout while reading the response from upstreamnginx stops waiting for PHP-FPM (fastcgi_read_timeout)Fix
    2. 2The failure comes at 30 seconds, or at the value of request_terminate_timeoutPHP or PHP-FPM terminates the script before it finishesFix

What does the error look like?

  • net::ERR_INCOMPLETE_CHUNKED_ENCODING
  • The page loads partly, then the response stops

Cause 1 of 2

nginx stops waiting for PHP-FPM (fastcgi_read_timeout)

1Check

nginx's fastcgi_read_timeout defaults to 60 seconds. It applies between two reads, and when PHP sends nothing for that long, nginx closes the connection. A closed connection before the last chunk is, by RFC 9112, an incomplete message, which the browser reports.

grep -rn "fastcgi_read_timeout" /etc/nginx/
sudo tail -n 20 /var/log/nginx/error.log | grep -i timed

2Fix

Make the slow request faster, or raise the timeout for that location only.

location ~ \.php$ {
    fastcgi_pass unix:/run/php/php-fpm.sock;
    fastcgi_read_timeout 180s;
}

3Verify

The slow request completes in curl with the expected size.

sudo nginx -t && sudo systemctl reload nginx && curl -sS -o /dev/null -w '%{http_code} %{size_download}\n' https://example.com/slow-report.php

Confirmed by nginx.org

Did this fix it?

Cause 2 of 2

PHP or PHP-FPM terminates the script before it finishes

1Check

max_execution_time defaults to 30 seconds for web requests and ends the script when exceeded. PHP-FPM's request_terminate_timeout kills the worker for a request after its limit; its default 0 means off.

php -r 'echo ini_get("max_execution_time"), "\n";'
grep -rn "request_terminate_timeout" /etc/php/

2Fix

Raise max_execution_time for the script that needs it, and make sure request_terminate_timeout is not lower than it. Better, move the long job to a queue and return at once.

<?php
set_time_limit(120); // at the top of the long-running script

3Verify

The request now returns a full response.

curl -sS -o /dev/null -w '%{http_code} %{size_download}\n' https://example.com/slow-report.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Keep web requests short; run reports and exports in a background job and send the user a link.
  • Log the duration of slow requests, so a timeout is found before users see it.
  • When you raise one timeout, check the others in the chain (nginx, PHP-FPM, PHP, any proxy).

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

CodeIgniter works locally but every page is 404 on the live server

The requested URL was not found on this server.

A 404 on the live server comes from one of four places: the document root is not the public folder, Apache ignores .htaccess or nginx has no try_files rule, the route is not defined because auto routing is off, or the controller file name differs from its class in case.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.