From 638993442a3ef0829c3a6fdd590adeb10cfb8c75 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 23 Mar 2014 21:36:11 +0100 Subject: update documentation --- documentation/output-and-errors.html | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'documentation') diff --git a/documentation/output-and-errors.html b/documentation/output-and-errors.html index 4697854..b5097ca 100644 --- a/documentation/output-and-errors.html +++ b/documentation/output-and-errors.html @@ -1,28 +1,29 @@

Output and errors

- You can use regular C++ streams for IO. It is however not - a good idea to use the std::cout and std::cerr streams for output. + You can use regular C++ streams for IO, with the regular << operator + and special functions like std::endl. It is however not a good idea to use + the 'std::cout' and 'std::cerr' streams.

When PHP runs as a webserver module, stdout is redirected to the - terminal from where the webserver process was originally started, - while you probably want to generate output that ends up in the generated - (HTML) output. But even when PHP runs as a CLI script - and std::cout works - - you still should not write to stdout directly, because it will bypass all - output handlers that may have been set up by the PHP user space script. + terminal from which the webserver process was originally started. + On production servers such a terminal is not active, so any output that + you send to stdout will be lost. Using std::cout in extensions that run in + a webserver module is thus a no-go. But even when PHP runs as a CLI script + (and std::cout does work) you still should not write to stdout + directly. Writing to stdout will bypass all output handlers that may have + been set up by the PHP user space script.

The PHP-CPP library offers a Php::out stream that can be used instead. This Php::out variable is an instance of the well known std::ostream class, and - utilizes all the output buffering set up in PHP. All output that you send to - it always ends up where you expect: on stdout for CLI scripts, and in the - generated code for webserver processes. It does essentially the same + respects all the output buffering set up in PHP. It does essentially the same as the echo() function in PHP scripts.

- Php::out is a regular std::ostring object. This also has as consequence that - it uses a buffer that needs to be sync'ed to flush the output. This flush - happens automatically when you add 'std::endl' to the output, or when you + Php::out is a regular std::ostream object. This has as consequence that + it uses an internal buffer that needs to be flushed. This flushing + occurs automatically when you add 'std::endl' to the output, or when you add 'std::sync' explicitly.

@@ -42,7 +43,8 @@ void example() Php::out << "example output"; Php::out.flush(); - // just like all PHP functions, the Php::echo() function can also be used + // just like all PHP functions, you can call the echo() function + // from C++ code as well Php::echo("Example output\n"); } -- cgit v1.2.3