Skip to content

Built in server with PHP_CLI_SERVER_WORKERS is broken in php > 8.0.2 #9400

Closed

Description

@erjotek

Description

I don't known if it's problem with chrome 104 (because firefox/vivaldi works) or with php, but is impossible to serve index.html with php 8.0.22 or php 8.1.9 and PHP_CLI_SERVER_WORKERS >2

It's impossible to serve this index.html with php >8.0.2 with PHP_CLI_SERVER_WORKERS >2

Everything works with php7.4.30

The following code:

index.html:

<html>
<script src='test.js?1'></script>
<script src='test.js?2'></script>
<script src='test.js?3'></script>
<script src='test.js?4'></script>
<script src='test.js?5'></script>
<script src='test.js?6'></script>
<script src='test.js?7'></script>
<script src='test.js?8'></script>
<script src='test.js?9'></script>
<script src='test.js?10'></script>
<script src='test.js?11'></script>
<script src='test.js?12'></script>
<script src='test.js?13'></script>
<script src='test.js?14'></script>
<script src='test.js?15'></script>
<script src='test.js?16'></script>
</html>

<body>
Finish...
</body>
  1. create file index.html
  2. start php 8.1.9 PHP_CLI_SERVER_WORKERS=2 php8.1 -S localhost:8081
  3. open http://localhost:8081 in Chrome 104.0.5112.101

PHP Version

8.0.22 , 8.1.9

Operating System

Ubuntu 20.04

Activity

  1. cmb69 commented on Aug 22, 2022

    @cmb69
    Member

    but is impossible to serve index.html with php 8.0.22 or php 8.1.9 and PHP_CLI_SERVER_WORKERS >2

    What happens? Does PHP hang? Does PHP crash? Does PHP serve nonsense?

  2. erjotek commented on Aug 22, 2022

    @erjotek
    Author

    @cmb69

    There is no crash but browser is waiting for finish request.

    To finish request i need open new tab with new connection - than previous one is completed but new connection is waiting

    without server workers everything works

    Strace info:

    strace: Process 268011 attached
    select(5, [4], [], NULL, {tv_sec=0, tv_usec=545118}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    select(5, [4], [], NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout)
    

    I think it's important that Ctrl+C to stop server doesn't work ([php8.1] <defunct>)

    image

  3. erjotek commented on Aug 23, 2022

    @erjotek
    Author

    @cmb69 I did more tests...

    The problem started in 8.0.3, possibly due to fix for #80723.
    PHP version 7.4.x and 8.0.0-8.0.2 are ok.

    This problem is not related to chrome, it also occurs with firefox

  4. changed the title [-]PHP_CLI_SERVER_WORKERS with chrome 104[/-] [+]Built in server with PHP_CLI_SERVER_WORKERS is broken in php > 8.0.2[/+] on Aug 23, 2022
  5. cmb69 commented on Aug 23, 2022

    @cmb69
    Member

    I can confirm that some requests may hang; that does apparently not happen if index.php is explicitly added to the URL.

  6. erjotek commented on Aug 23, 2022

    @erjotek
    Author

    @cmb69

    It doesn't matter if index.php is in the url or not. It depends on the number of simultaneous connections.

    This issue does not occur with a single thread PHP server (without PHP_CLI_SERVER_WORKERS)

    Check it (the .jpg files don't even have to exist):

    index.php:

    <html>
    <head>
    <title>PHP Bug #9400</title>
    </head>
    
    <body>
    <?php for($i=0;$i<60;$i++) echo "<img src='/test$i.jpg?".time()."$i'>"; ?>
    Finish...
    </body>
    </html>

    docker-compose.yml

    version: '3.9'
    services:
      php:
    #    image: php:8.1.9-cli-alpine
        image: php:8.1.9-cli
        volumes:
          - .:/app
        command: ['-S', '0.0.0.0:8080', '-t', '/app']
        ports:
          - "8080:8080"
        environment:
          PHP_CLI_SERVER_WORKERS: 4
    
    1. docker compose up
    2. Open http://127.0.0.1:8080/
  7. Erwane commented on Sep 7, 2022

    @Erwane

    I can confirm this bug.
    With php 8.1.9 on ubuntu, when PHP_CLI_SERVER_WORKERS connection may hang forever (no timeout ??) and browser wait for connection to close.

    In dev tool network tab, some connections are in a waiting state.

    How to reproduce :

    composer create-project --prefer-dist cakephp/app:4.* app
    cd app
    PHP_CLI_SERVER_WORKERS=2 /usr/bin/php8.1 -S localhost:8080 -t webroot webroot/index.php
    

    go to : http://localhost:8080/ in a chromium web browser (brave)
    Very long time to load

    Without PHP_CLI_SERVER_WORKERS, page load is instant.

    Thanks.

    /usr/bin/php8.1 --version

    PHP 8.1.9 (cli) (built: Aug 15 2022 09:40:11) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.9, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.9, Copyright (c), by Zend Technologies
        with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethan
    

    /usr/bin/php8.1 -m

    [PHP Modules]
    apcu
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    FFI
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    json
    libxml
    mailparse
    mbstring
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    Phar
    posix
    readline
    Reflection
    rrd
    session
    shmop
    SimpleXML
    sockets
    sodium
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tokenizer
    xdebug
    xml
    xmlreader
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Xdebug
    Zend OPcache
    
  8. self-assigned this
    on Sep 7, 2022
  9. andypost commented on Sep 30, 2022

    @andypost
    Contributor

    Used to face it few times with custom docker images, but no xdebug was enabled. Drupal using build-in server for quick-start so not easy to catch

  10. added a commit that references this issue on Oct 20, 2022
    d52f045
  11. added a commit that references this issue on Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions