New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headers functions do nothing in CLI SAPI #12304
Comments
Personally, I would rather prefer that all HTTP functionality not applicable in CLI threw exceptions instead of quietly not working. Same for vice versa: CLI functions in HTTP SAPIs. |
Alternatively I hope that header functions can be removed completely in the CLI so that users can create a custom |
You can override it, in PHP8.0. Like I do in my project https://github.com/joanhey/AdapterMan. But later you need an spiral of changes: setcookie, Session, http_response_code, ... We can use the same In reality all the php-src session tests are using the CLI SAPI. php-src/ext/session/tests/gh9200.phpt Lines 7 to 17 in be27543
We need later only a small change in the session, to clean the session_id. With that small change, we can use headers, setcookie and sessions from CLI, without write a line of code. |
For now I ended up using |
Description
It seems an stupid issue, but please read.
Related to #12303
The following code:
Resulted in this output:
But I expected this output instead:
We know that the CLI SAPI don't send headers, and for that it's OK that the
sapi_cli_send_headers()
do nothing.https://github.com/php/php-src/blob/master/sapi/cli/php_cli.c#L395-L405
But all the other
header()
,header_remove()
,headers_list()
that depend fromsapi_cli_header_handler()
https://github.com/php/php-src/blob/master/sapi/cli/php_cli.c#L389-L392
can work normally from CLI using the fallback. Only the
headers_sent()
need to be alwaysfalse
.https://github.com/php/php-src/blob/master/sapi/cli/php_cli.c#L446-L448
Related to #12303
https://3v4l.org/Wub2V
Actual behavior
https://3v4l.org/vZtmZ
Yes, it's curious that the
setcookie()
returntrue
.And the
http_response_code()
also work from CLI, we only need to set the initial value, but not the headers.First because other php functions use it internally, like setcookie, session, ...
But it's more important to use php files without changes from CLI.
Basic example:
So we can use any PHP file from CLI and send it to any socket.
Actually we need to create custom functions to manage the headers, and change the normal php files.
But with the
headers_list()
andhttp_response_code()
we can create all the http message.BC: Nothing
That functions now do nothing from CLI.
If accepted it'll be good to be added to all php supported versions.
PHP Version
All
Operating System
All
The text was updated successfully, but these errors were encountered: