PHP built-in WebServer inquiry (2) custom PHP console output console function, webconsole_PHP tutorial

Source: Internet
Author: User
PHP built-in WebServer inquiry (2) custom PHP console output console function, webconsole. PHP built-in WebServer inquiry (2) custom PHP console output console function, webconsole we are developing APP server side, when performing joint debugging with the APP, you often need to track URL requests in real time and PHP built-in Web Server inquiry (2) custom PHP console output console function, webconsole

We often need to track the receipt of URL requests and parameters in real time when performing joint debugging with the APP on the APP server.

However, PHP does not have console output functions such as Python or Java, Python print () and Java System. out. println (), PHP echo, print and other functions directly use php-f index. php can be printed on the shell screen, but the debugging information cannot be printed only in the shell but not in the browser when the cli_server is running.

After searching for a long time, I found little information about the built-in server cli mode of PHP on the Internet, and I couldn't find any useful information.

After reading the official PHP documentation, I finally thought of the PHPSTDOUT

Php: // outputIs a write-only data stream that allows you to write data to the output buffer in the same way as print and echo.

When running in cli mode, as long as data is written to STDOUT, echo or print is not required, it is immediately printed to the SHELL client:

Therefore, we can write a custom function to encapsulate the data in the sdtout standard output stream, which is equivalent to printing the scheduling information to the shell at any time:

1/* 2 * The cli mode or built-in server prints debugging information, and does not output the 3 * param fixed $ data parameter in the browser. it can be all data types except objects, such as strings, array, jason, etc. 4 */5 function console ($ data) {6 $ stdout = fopen ('php: // stdout ', 'w'); 7 fwrite ($ stdout, json_encode ($ data ). "\ n"); // format all data into a Json string 8 fclose ($ stdout) to make the printed format clearer; 9}

When you need to print the current debugging information after each request of the built-in Server: directly call console ().

For example:

Print all received GET or POST parameters:

Console ($ _ GET );

Console ($ _ POST );

  

Print string:

Console ("hello php console debug ");

  

In the future, you no longer need to envy the console output of Python and Java. PHP also has console output functions.

Login Server (II) custom PHP console output console function. webconsole we are developing the APP Server. when performing joint debugging with the APP, we often need to track URL requests in real time and...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.