WSL: Nginx w/ PHP-FPM 7.1 FastCGI w/ a Unix Socket hangs when fastcgi_buffering: on (default)

  • Windows build number: Microsoft Windows [Version 10.0.17134.285]

  • What I’m doing and what’s happening: Install PHP 7.1, follow normal Ubuntu guide on doing it. Create a test index.php with the contents:

<?php
phpinfo();

Visit localhost:80 or localhost:443

  • What’s wrong / what should be happening instead: Page loads half-way and hangs.

  • Current hack / workaround

Turn off fastcgi_buffering as per below:

location ~ \.php$ {
        proxy_set_header X-Forwarded-Proto $scheme;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_buffering off; # This must be here for WSL as of 11/28/2018
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "upload_max_filesize = 20M \n post_max_size=21M";
        include /etc/nginx/fastcgi.conf;
}

Not sure exactly what the issue is but it’s probably something to do with how WSL handles unix sockets.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 10
  • Comments: 17

Commits related to this issue

Most upvoted comments

This is still an issue on 1909 (Build 18363.535)

workaround:

fastcgi_buffering off;

I’m using WSL1, php 7.4 and nginx. Had the same issue. I did what @amiletti did, it didn’t fix my issues…

However, adding these into my http block of nginx.conf fixed it. I don’t know much about nginx/configuration, but it solved my issue for local dev atleast

        client_body_buffer_size 1024k;
        client_header_buffer_size 1024k;
        client_max_body_size 100m;

client_body_buffer_size seemed to be the main issue, but the others are safe-guards I guess.

WSL with:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

nginx version: nginx/1.18.0 (Ubuntu)

PHP 8.1.5 (cli) (built: Apr 21 2022 10:14:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

PHP 8.1.5 (fpm-fcgi) (built: Apr 21 2022 10:14:45)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

same error on 2022/05/22.

work around with nginx config:

        fastcgi_buffering off;
        proxy_buffering off;

This is still an issue on 1903 (Build 18362.113)

It seems wrong… but it works 😛

fastcgi_buffering off;

fastcgi_buffer_size 2M;
fastcgi_buffers 8 2M;

I had the same issue, when I print out a page, only the first part of the page is actually printed and the browser remains in loading state until nginx reaches timeout (I think).

I had this problem on a fresh installation of Ubuntu 20.04 on wsl 1 and PHP 7.4.

Based on Remi-Coulom advice and nginx documentation, I tried to increase fastcgi_buffer_size and fastcgi_buffers in “vhost” location PHP block and it seems to solve my problem.

location ~ \.php$ {
    
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 64k;
    #fastcgi_buffering off;

    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}

I want to report that in my case fastcgi_buffering off doesn’t seem related to the problem. I hope this helps.

epoll_wait(12,  <detached ...>`

Great, thanks. I take it that last epoll_wait() simply never returns. There have been fixes to somewhat similar issues in 1809, although I can’t pin your sequence on an exact dupe. See #3100 #2949 #2846 et al.

Well luckily I encountered this while writing our dev on boarding guide for Windows so I can copy/paste the relevant parts.

Setup Ubuntu Environment in Windows

  1. Install Windows Subsystem for Linux

    https://docs.microsoft.com/en-us/windows/wsl/install-win10

  2. Install Ubuntu from the Windows Store or Install Manually

    https://docs.microsoft.com/en-us/windows/wsl/install-manual

  3. Continue normal Ubuntu setup instructions

Install PHP for Ubuntu

  • sudo apt install software-properties-common - gets the add-apt-repository command
  • sudo add-apt-repository ppa:ondrej/php
  • sudo add-apt-repository ppa:ondrej/nginx
  • sudo apt update - Updates your list of available packages
  • sudo apt install php7.1 php7.1-bcmath php7.1-bz2 php7.1-cli php7.1-curl php7.1-dba php7.1-fpm php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-readline php7.1-soap php7.1-xml php7.1-zip php-gnupg php-pear php-memcached php-msgpack php-igbinary - Install PHP 7.1 and all extensions we absolutely need

At this point php -v should work from terminal and the ubuntu service php7.1-fpm should be registered and started. It should already be listening on /run/php/php7.1-fpm.sock.

Configure php-fpm

  • sudo nano /etc/php/7.1/fpm/php.ini
  • Change this value and save the file.
  • cgi.fix_pathinfo=0
  • sudo service php7.1-fpm restart

Install Nginx

  • sudo apt install nginx
  • sudo service nginx start

Edit the default site:

  • sudo nano /etc/nginx/sites-available/default

In the server bracket add this:

server {
        .... other settings ...
    location ~ \.php$ {
            proxy_set_header X-Forwarded-Proto $scheme;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PHP_VALUE "upload_max_filesize = 20M \n post_max_size=21M";
            include /etc/nginx/fastcgi.conf;
    }
}
  • sudo service nginx restart

strace

To gather this strace I lowered the nginx workers to 1 and attached to that one. Then I visited /info.php which was a page containing the phpinfo(); standard output.

gettimeofday({1543459478, 202784}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 705916000}) = 0
accept4(10, {sa_family=AF_INET, sin_port=htons(55093), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_NONBLOCK) = 3
epoll_ctl(12, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLRDHUP|EPOLLET, {u32=2971141072, u64=140667445052368}}) = 0
epoll_wait(12, [{EPOLLIN, {u32=2971141072, u64=140667445052368}}], 512, 60000) = 1
gettimeofday({1543459478, 204963}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 708132000}) = 0
recvfrom(3, "\26", 1, MSG_PEEK, NULL, NULL) = 1
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
read(3, "\26\3\1\0021\1\0\2-\3\3\227\201\317\6\263_\265\7\244=\2207~\246c\3736\316\234#\361"..., 16709) = 566
time(NULL)                              = 1543459478
time(NULL)                              = 1543459478
time(NULL)                              = 1543459478
time(NULL)                              = 1543459478
write(3, "\26\3\3\0d\2\0\0`\3\3h?\274\177K\324R\334s\226\254\37\206\337\207\353kX(\250+"..., 156) = 156
read(3, 0x7fffbaae0363, 16709)          = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(12, [{EPOLLIN, {u32=2971141072, u64=140667445052368}}], 512, 59997) = 1
gettimeofday({1543459478, 207112}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 710144000}) = 0
read(3, "\24\3\3\0\1\1\26\3\3\0(\0\0\0\0\0\0\0\0\261(\333\210`\316\234\363\262Gw*\34"..., 16709) = 51
read(3, 0x7fffbaadae03, 16709)          = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(12, [{EPOLLIN, {u32=2971141072, u64=140667445052368}}], 512, 59995) = 1
gettimeofday({1543459478, 211616}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 714673000}) = 0
read(3, "\27\3\3\5[\0\0\0\0\0\0\0\1\263\312bso\222\264\n\3068ZJ\267QC\16\302\253\1"..., 16709) = 1376
read(3, 0x7fffbaadae03, 16709)          = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(12, EPOLL_CTL_MOD, 3, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=2971141072, u64=140667445052368}}) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 14
ioctl(14, FIONBIO, [1])                 = 0
epoll_ctl(12, EPOLL_CTL_ADD, 14, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=2971141313, u64=140667445052609}}) = 0
connect(14, {sa_family=AF_LOCAL, sun_path="/var/run/php/php7.1-fpm.sock"}, 110) = 0
getsockopt(14, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
writev(14, [{"\1\1\0\1\0\10\0\0\0\1\0\0\0\0\0\0\1\4\0\1\t.\2\0\f\0QUERY_"..., 2392}], 1) = 2392
epoll_wait(12, [{EPOLLOUT, {u32=2971141072, u64=140667445052368}}, {EPOLLOUT, {u32=2971141313, u64=140667445052609}}], 512, 60000) = 2
gettimeofday({1543459478, 213736}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 716770000}) = 0
epoll_wait(12, [{EPOLLIN, {u32=2971141313, u64=140667445052609}}], 512, 59998) = 1
gettimeofday({1543459478, 216843}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 719885000}) = 0
recvfrom(14, "\1\6\0\1\0*\6\0Content-type: text/html;"..., 4096, 0, NULL, NULL) = 4096
readv(14, [{"v+Inu8UdKnmkEUHQK93EjEZ4Rbkifq8J"..., 4096}], 1) = 4096
readv(14, [{"onf.d/20-ftp.ini,\n/etc/php/7.1/f"..., 4096}], 1) = 4096
readv(14, [{"WZvEK7Dnf6WUljTT5TS7d0KwezkJShdW"..., 4096}], 1) = 4096
readv(14, [{"cupaIoEz6EmaC3C+0Ro6Wgp4eb2tpPJq"..., 4096}], 1) = 4096
readv(14, [{"fault_charset</td><td class=\"v\">"..., 4096}], 1) = 4096
readv(14, [{" class=\"v\"><i>no value</i></td><"..., 4096}], 1) = 4096
readv(14, [{"=\"e\">zend.assertions</td><td cla"..., 4096}], 1) = 4096
readv(14, [{"class=\"h\"><th>Directive</th><th>"..., 4096}], 1) = 4096
mmap(NULL, 274432, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fefb1130000
readv(14, [{"</tr>\n<tr><td class=\"e\">WebP Sup"..., 4096}, {"s=\"e\">Multibyte regex (oniguruma"..., 4096}, {"r>\n<tr><td class=\"e\">memcached.s"..., 4096}, {"td class=\"v\">Off</td><td class=\""..., 4096}, {"ormal </td><td class=\"v\">329 </t"..., 4096}, {"/td><td class=\"v\">1 </td></tr>\n<"..., 4096}, {"ass=\"e\">com_table_dump </td><td "..., 4096}, {"09 Tim Kientzle.</td></tr>\n</tab"..., 4096}, {"ogress.name</td><td class=\"v\">PH"..., 4096}], 9) = 36864
write(3, "\27\3\3@\30Xwi\24\231\251\210Y\350\372\335\236!\217w\314\3072\323\316\",R\335\330)l"..., 16413) = 16413
readv(14, [{"\">0</td><td class=\"v\">0</td></tr"..., 4096}, {"r><td class=\"e\">xdebug.dump_unde"..., 4096}, {"s</td><td class=\"v\">0</td><td cl"..., 4096}, {"=\"e\">opcache.file_update_protect"..., 4096}, {"434.1543280177434.1</td></tr>\n<t"..., 4096}, {"_SERVER['HTTPS']</td><td class=\""..., 4096}, {"/td></tr>\n<tr><td class=\"e\">Cale"..., 4096}, {"ory Beaver, Marcus Boerger </td>"..., 4096}, {"><th colspan=\"2\">Websites and In"..., 4096}], 9) = 33976
epoll_wait(12, [{EPOLLRDHUP, {u32=2971141313, u64=140667445052609}}], 512, 59995) = 1
gettimeofday({1543459478, 221596}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808013, 724646000}) = 0
epoll_wait(12, [{EPOLLIN, {u32=2971140592, u64=140667445051888}}], 512, 59990) = 1
gettimeofday({1543459479, 599371}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808015, 102433000}) = 0
accept4(10, {sa_family=AF_INET, sin_port=htons(55094), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_NONBLOCK) = 15
epoll_ctl(12, EPOLL_CTL_ADD, 15, {EPOLLIN|EPOLLRDHUP|EPOLLET, {u32=2971141552, u64=140667445052848}}) = 0
epoll_wait(12, [{EPOLLIN|EPOLLRDHUP, {u32=2971141552, u64=140667445052848}}], 512, 58612) = 1
gettimeofday({1543459479, 600182}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808015, 103214000}) = 0
recvfrom(15, "", 1, MSG_PEEK, NULL, NULL) = 0
close(15)                               = 0
epoll_wait(12, [], 512, 58611)          = 0
gettimeofday({1543459538, 212810}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC_COARSE, {808073, 715869000}) = 0
gettid()                                = 12638
write(7, "2018/11/28 21:45:38 [error] 1263"..., 284) = 284
close(14)                               = 0
write(3, "\27\3\3.\352Xwi\24\231\251\210Z\244\306\21\207\241RS\216d\332\202\232\23\241\312\177\324\336\322"..., 12015) = 12015
write(4, "127.0.0.1 - - [28/Nov/2018:21:45"..., 163) = 163
munmap(0x7fefb1130000, 274432)          = 0
write(3, "\25\3\3\0\32Xwi\24\231\251\210[\5\324\326\373=\265,Q>\353?\33*\245\343\335}!", 31) = 31
close(3)                                = 0
epoll_wait(12,  <detached ...>

During this time /var/log/nginx/error.log recorded this:

2018/11/28 21:45:38 [error] 12638#12638: *4 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "localhost"