Skip to content

PHP exit; fails to produce a CGI response #24

@fd

Description

@fd

When exit; is called and the headers have not yet been flushed the CGI response is completely empty.
The issue seems to be that the shutdown procedures are not called on exit;.

Reproduction

<?php
// test-exit-flush-fail.php
header('X-Test: 123');
exit;
<?php
// test-exit-flush-ok.php
header('X-Test: 123');
// Note: at least one byte needs to be sent.
echo "X";
exit;

When I run the scripts with a native php-cgi binary it produces the expected CGI responses.

> docker run --rm -ti -v $PWD:/app php:7.4.32-cli /usr/local/bin/php-cgi /app/test-exit-flush-ok.php
X-Powered-By: PHP/7.4.32
X-Test: 123
Content-type: text/html; charset=UTF-8

X
> docker run --rm -ti -v $PWD:/app php:7.4.32-cli /usr/local/bin/php-cgi /app/test-exit-flush-fail.php
X-Powered-By: PHP/7.4.32
X-Test: 123
Content-type: text/html; charset=UTF-8

But when I run the test-exit-flush-fail.php with wasmtime it fails to produce a CGI response.

> wasmtime --mapdir=./::./ php-cgi -- test-exit-flush-ok.php 
X-Powered-By: PHP/7.4.32
X-Test: 123
Content-type: text/html; charset=UTF-8

X
> wasmtime --mapdir=./::./ php-cgi -- test-exit-flush-fail.php 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions