====== PHP HTTP Response Handling Summary ====== See [[java:HttpServletResponse]] for more information on how Java handles HTTP Responses. See [[HTTP Request Handling]] for more information on how PHP handles HTTP requests. ===== HTTP Response Content ===== PHP has a fairly simple output mechanism compared to Java Servlets. * [[phpfn>print]] - Output one or more strings * [[phpfn>printf]] - Output formated strings * [[phpfn>echo]] - Output one or more strings (as a function) The [[http://us2.php.net/manual/en/ref.outcontrol.php|Output Control Functions]] provide control over the buffering of the content output of the request. They also provide a simple mechanism to stack output filters. See InterceptingFilter. * [[phpfn>flush]] - Flush the output buffer ( useful to give end users the impression of realtime updates - see [[http://ben.milleare.com/archives/000210.html|The Joy of Flush]] for details and PEAR::HTML_Progress [[http://pear.laurent-laville.org/HTML/Progress/examples/index.html|examples]]) * [[phpfn>ob_clean]] - Clean (erase) the output buffer * [[phpfn>ob_end_clean]] - Clean (erase) the output buffer and turn off output buffering * [[phpfn>ob_end_flush]] - Flush (send) the output buffer and turn off output buffering * [[phpfn>ob_flush]] - Flush (send) the output buffer * [[phpfn>ob_get_clean]] - Get current buffer contents and delete current output buffer * [[phpfn>ob_get_contents]] - Return the contents of the output buffer * [[phpfn>ob_get_length]] - Return the length of the output buffer * [[phpfn>ob_get_level]] - Return the nesting level of the output buffering mechanism * [[phpfn>ob_get_status]] - Get status of output buffers * [[phpfn>ob_implicit_flush]] - Turn implicit flush on/off * [[phpfn>ob_start]] - Turn on output buffering * [[phpfn>mb_output_handler]] - Callback function converts character encoding in output buffer output buffer configuration settings (ini) * ''output_buffering'' - enable buffering for all requests * ''output_handler'' - Register an output handling function. Same as ob_start. * ''implicit_flush'' - flush output after every output block (echo, print or printf) [[http://www.php.net/manual/en/ref.session.php|Session Handling Functions]] provide the capability to use url based session Ids in the content output. * ''session.use_trans_sid'' - when this option is enabled, relative URIs in the response output will be rewritten to contain a session Id. * ''url_rewriter.tags'' - specifies which html tags are rewritten to include session information. The [[http://www.php.net/manual/en/ref.zlib.php|Zlib Compression Functions]] can compress output on-the-fly. * [[phpfn>ob_gzhandler]] - ob_start callback function to gzip output buffer * [[phpfn>zlib_get_coding_type]] - Returns the coding type used for output compression Zlib compression configuration options: * ''zlib.output_compression'' - Whether to transparently compress pages * ''zlib.output_compression_level'' - Compression level used for transparent output compression * ''zlib.output_handler'' - similiar to output_handler ===== HTTP Response Headers ===== Basic [[http://us2.php.net/manual/en/ref.http.php|HTTP Functions]]. * [[phpfn>header]] - Send a raw HTTP header * [[phpfn>setcookie]] - Send a cookie (see [[http://www.php.net/manual/en/features.cookies.php|Cookies]]) * [[phpfn>headers_sent]] - Checks if or where headers have been sent * [[phpfn>apache_response_headers]] - Fetch all HTTP response headers (see [[http://www.php.net/manual/en/ref.apache.php|Apache specific functions]]) Output compression configuration * ''zlib.output_compression'' - outputs ''Content-Encoding'' and ''Vary'' headers when content is compressed. Several configuration options control how the php session handling functions output cookies for tracking sessions. * ''session.auto_start'' - specifies whether the session module starts a session automatically * ''session.name'' - Used as the cookie name * ''session.cookie_lifetime'' - How long should the browser store the cookie * ''session.cookie_path'' * ''session.cookie_domain'' * ''session.cookie_secure'' * ''session.use_cookies'' - specifies whether the module will use cookies to store the session id on the client side * ''session.use_only_cookies'' - specifies whether the module will only use cookies to store the session id on the client side functions controling how cookies are output during session handling. * [[phpfn>session_set_cookie_params]] - Set the session cookie parameters * [[phpfn>session_get_cookie_params]] - Get the session cookie parameters Configuration options controlling page caching during a session: * ''session.cache_limiter'' - specifies cache control method to use for session page * ''session.cache_expire'' - specifies time-to-live for cached session pages Functions controlling page caching during a session: * [[phpfn>session_cache_limiter]] - Get and/or set the current cache limiter * [[phpfn>session_cache_expire]] - Return current cache expire [[http://www.php.net/manual/en/ref.apache.php|Apache specific functions]] configuration options * ''last_modified'' - send PHP scripts modification date as ''Last-Modified:'' header for the request. ===== HTTP Response Status ===== The [[phpfn>header]] function has special case logic to also set the response status code. When the header paramter to the header() function begins with HTTP/, Status:, or Location:, the HTTP response status code is modified. See [[http://www.php.net/manual/en/features.http-auth.php|HTTP authentication with PHP]] for more information about setting the response status. ===== Web Server Interface ===== [[http://www.php.net/manual/en/ref.apache.php|Apache specific functions]] for response processing * [[phpfn>apache_child_terminate]] - Terminate apache process after this request * [[phpfn>apache_lookup_uri]] - Perform a partial request for the specified URI and return all info about it * [[phpfn>apache_setenv]] - Set an Apache subprocess_env variable * [[phpfn>virtual]] - Perform an Apache sub-request ===== HTTP Response Header / PHP Cross Reference ===== ==== Content-Encoding ==== The ''zlib.output_compression'' configuration option or [[phpfn>ob_gzhandler]] output handler can output Content-Encoding: gzip or Content-Encoding: deflate headers. ==== Content-Length ==== The ''zlib.output_compression'' configuration option or [[phpfn>ob_gzhandler]] output handler can output ''Content-Length'' headers. ==== Content-Type ==== The [[phpfn>mb_output_handler]] function and the configuration option ''mbstring.http_output'' can add charset information to the ''Content-Type'' headers. ==== Last-Modified ==== The ''last_modified'' configuration option send PHP scripts modification date as ''Last-Modified:'' header for the request. See [[http://www.php.net/manual/en/ref.apache.php|Apache specific functions]]. ==== Set-Cookie ==== The [[phpfn>setcookie]] function is the standard API for developers to output this header. PHP [[http://www.php.net/manual/en/ref.session.php|Session Handling Functions]] Will also set a cookie for tracking session Ids. ==== Vary ==== The ''zlib.output_compression'' configuration option or [[phpfn>ob_gzhandler]] output handler can output ''Vary: Accept-Encoding'' headers.