google-chromelaravelnginxdebianphp-5.6

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING


I've been having some problems with my application not loading the views (sometimes). I am running a Debian server with php-fpm and nginx (php5.6.8 and nginx 1.8.0) Both compiled from source. On top of that I am running Lavavel 4.2.

So far I've had the problem in both Chrome and Firefox (chrome simply stops loading and shows the error, firefox does not show an error but shows a incomplete version of the view).

So far I've checked the permissions of both nginx and PHP, they both run as the same user (www-data:www-data). My php-fpm socket is configured as:

[sitename]

listen = /var/run/php5-fpm/sitename.sock
listen.backlog = -1
listen.owner = www-data
listen.group = www-data
listen.mode=0660

; Unix user/group of processes
user = folderuser
group = www-data

; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Note that I set user to folderuser because the folder where the files for the site are located is owned by folderuser (folderuser:www-data). Furthermore, permissions inside laravel folders are configured as 755 (775 for cache and upload folders so that www-data can write cache files)

I have disabled any kind of serverside php cache (except for zend opcache).

I've also tried disabling "prefetch resources to load pages more quickly" feature in chrome, which did not solve the problem.

As a last resort I've tried this solution:

/*
|--------------------------------------------------------------------------
| Fix for Chrome / PHP 5.4 issue
| http://laravel.io/forum/02-08-2014-another-problem-only-with-chrome
|--------------------------------------------------------------------------
*/

App::after(function($request, $response)
{

    $content = $response->getContent();

    $contentLength = strlen($content);

    $response->header('Content-Length', $contentLength);

});

And some variants to this script, but I got some content length mismatches (more often than the net::ERR_INCOMPLETE_CHUNKED_ENCODING errors.

So to sum up, I've checked permissions and user/group settings serverside, I've disabled serverside caching (except for zend), I've messed around with chrome settings and I've tried a script for laravel, none of which solved the issue I am having. Note that the issue happens at random intervals at random pages on the site.

I really do not know what the next step towards solving my problem would be as the solutions above are the only ones I've found on the internet.

I would really appreciate some help.

Edit: I have a beta version of the same application running off another server with the exact same configuration (only difference is in hardware, more memory though), the issue does not present there.

Also, I forgot the mention that the application does not run with HTTPS (currently). The beta version however is running with HTTPS.

Edit The server where the issue is present has 2048 MB RAM, the beta server has 8192 MB RAM.

Edit I inspected the response with fiddler when the error occured, it simply cuts of the response at some point for no reason.


Solution

  • You might want to check if the folder /var/lib/nginx is owned by www-data too. I had this problem that, when the response page was too big, the Nginx worker process tried to use this folder and failed, because it was owned by nginx and the worker process ran under www-data. By doing chown -R www-data:www-data /var/lib/nginx, the problem was fixed.