Hi,
I created a issue https://github.com/php/php-src/issues/12304 and later
the PR https://github.com/php/php-src/pull/16145 about the headers in CLI.
But both remains stalled, so I'll present it here.

The CLI SAPI don't send headers, and for that it's OK that
the sapi_cli_send_headers() do nothing.
But we can't use the normal headers, cookies, session, ... functions
from CLI, that later we can take with the headers_list().

From PHP 8.0 we can disable the functions, and override them. But later
we need an spiral of changes: setcookie, session, ....
This problem is fixed with change only 1 line in the cli_sapi_module
from php-src:
  sapi_cli_header_handler,   /  header handler  /
for  
  NULL, / header handler /

So the CLI will use the fallback core header_handler and all the
functions will work with CLI, that now do nothing. And still the CLI
will never sent the headers.
This change don't break backward compatibility, as now all these
functions do nothing in CLI.
And I think that this change don't need an RFC.

In my project https://github.com/joanhey/AdapterMan we override them, to
demonstrate that is possible, and run with normal php files and frameworks.
But we need to waste a lot of time and effort to maintain it, when with
1 line changed in php-src it's ready.

This change it is not only for Adapterman, but to simplify the creation
of new CLI frameworks than improve the ecosystem.
Another benefit of this change is that we can test headers from CLI, now
we can't do it with phpunit, pest, ...

The PR come with tests, and also we run a compiled php with Adapterman
without problems.

Next Steps

Open more functions to CLI SAPI, like populate array from request data
stream, to simplify the creation of CLI frameworks.

Adapterman have demonstrated than CLI frameworks can be faster than C
frameworks like Swoole, Frankenphp, ... but we need to simplify the creation.

But this need an RFC.

Sincerely,
Joan Miquel Abrines

Reply via email to