1

As we know, there is the http_response_code function to get the response code from the server side by PHP, is there any implementation for similar function http_response_data to get the response data?

UPDATE: This http_response_data function will be called in the shutdown handler to track the whole website activity.

register_shutdown_function('shutdownHandler');
2
  • Just to be clear, you're looking for the data your server has written to the output buffer, but you've not yet finished running your PHP process/script so it hasn't actually been sent? Commented Dec 29, 2015 at 3:27
  • I've updated the question. I guess we sure know what we will send to the client at the script shutdown moment! Commented Dec 29, 2015 at 3:37

1 Answer 1

1

Generally, you put data into the response body by commands like echo or print. Using output buffering this data does not get immediately sent out to the client, but they get added to an output buffer. You can inspect and modify this buffer prior to it being sent back to the client via a number native PHP methods.

So, you can:

  • Enable an output buffer
  • Write to the buffer
  • Get a copy of the entire buffer contents when finished writing to it
  • Flush the buffer
  • Smile, drink soda, and eat some pie

From the register_shutdown_function() documentation:

The shutdown callbacks are executed as the part of the request, so it's possible to send output from them and access output buffers.

Here's the PHP documentation for manipulating the buffer: http://php.net/manual/en/book.outcontrol.php

A good overview of using the buffering functions is here: https://benramsey.com/articles/output-buffering/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.