-
Notifications
You must be signed in to change notification settings - Fork 34
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
Retrieve response code #47
Comments
Hi @proArtex! The answer is no and yes. :) NOIn general the client uses the FastCGI protocol to communicate with the FastCGI server, such as php-fpm. This protocol is not HTTP and does not know about response status codes by itself. YESI assume that you're using php-fpm as FastCGI server. As described in this comment of #27, there are four cases when php-fpm produces an HTTP status header with code 404 or 403. In any other case php-fpm does not produce a HTTP status header. As soon as your request hits a valid endpoint the server always answers with a plain text response that can include HTTP headers, if your endpoint set those headers. An example for a simple endpoint: /endpoint.php <?php
if ( isset( $_REQUEST['hello'] ) )
{
# Send header with HTTP status code 200 OK
header( 'Status: 200 OK');
echo "Hello {$_REQUEST['hello']}";
return;
}
# Send header with HTTP status code 400 Bad Request
header( 'Status: 400 Bad Request' );
echo "Bad Request, parameter 'hello' is missing."; That means you are responsible to send the right HTTP status codes if you want to use them in your application. The plain responses for this endpoint could look like this: /endpoint.php with QUERY_STRING: hello=proArtex X-Powered-By: PHP/7.3.5
Status: 200 OK
Content-type: text/html; charset=UTF-8
Hello proArtex /endpoint.php with empty QUERY_STRING X-Powered-By: PHP/7.3.5
Status: 400 Bad Request
Content-type: text/html; charset=UTF-8
Bad Request, parameter 'hello' is missing. Now that you have the status header sent, you can read it using the response object of the lib. $response->getHeader('Status'); I hope this answers your question. |
@hollodotme thanks for the answer! I actually want to add HEALTHCHECK to php-fpm docker container itself without web server (since it is in separate container). So I'm going to make a little cli wrapper and pack with phar so that I could use it like that:
What do you think, useful? |
Is there any way to get response status code?
The text was updated successfully, but these errors were encountered: