We are developing the server side of the app, and when it comes to the app, it's often necessary to keep track of URL requests and parameter reception in real time.
But PHP does not have a proprietary console output function like Python or Java, Python's print () and Java System.out.println (), PHP echo,print and other functions are used directly php-f Index.php can be printed on the shell screen, but the Cli_server runtime does not meet the debug information that is printed only in the shell and not displayed in the browser.
Use degree Niang search for a long time, on-line PHP built-in server CLI mode of data less, there is no useful information found.
By looking at the official PHP documentation, I finally thought of PHP's standard output stream STDOUT
php://outputis a write-only data stream that allows you to write to the output buffer in the same way as print and Echo
When running in CLI mode, whenever you write data to stdout, you do not need Echo or print to print to the shell client immediately:
Thus, we can write a custom function to encapsulate the data into the Sdtout standard output stream, which is equivalent to printing the dispatch information you want to display to the shell at any time:
1 /* 2 * CLI mode or built-in server print debug information, not browser output 3 * param fixed $data parameters can be all data types except objects, such as: strings, arrays, Jason, etc. 4*/5 function Console ($data) {6$stdoutfopen(' php:// StdOut ', ' W '); 7 fwrite ($stdout, Json_encode ($data). " \ n "); // to print out a clearer format, all data is formatted as a JSON string 8 fclose ($stdout); 9 }
When you need to print the current debug information after each request from the built-in server: Call the console () directly
Like what:
To print all received get or post parameters:
Console ($_get);
Console ($_post);
To print a string:
Console ("Hello PHP console Debug");
No more envy of Python and Java console output in the future, PHP also has a console output function.
The above describes the PHP built-in Web server to explore (ii) The custom PHP console output console function, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.