


Exploring PHP's built-in Web Server (2) Customizing the PHP console output console function, webconsole_PHP tutorial
Exploration of PHP’s built-in Web Server (2) Customizing the PHP console output console function, webconsole
We are developing the server side of the APP. When jointly debugging with the APP, we usually need Track 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’s System.out.println(), PHP’s echo, print and other functions can be used directly using php -f index. When using php, it can be printed on the shell screen, but when cli_server is running, it is not enough to print the debugging information only in the shell and not display it in the browser.
After searching with Du Niang for a long time, there is very little information on the PHP built-in server cli mode on the Internet, and I can't find any useful information at all.
After consulting the official PHP documentation, I finally thought of PHP’s Standard Output StreamSTDOUT
php://output is 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, as long as data is written to STDOUT, echo or print will be immediately printed to the SHELL client:
So, we can write a custom function to encapsulate the data input of the sdtout standard output stream, which is equivalent to printing the scheduling information we want to display to the shell at any time:
<span><span>1</span> <span>/*</span> <span>2</span> <span>* cli模式或者内置server打印调试信息,而不在浏览器输出 </span><span>3</span> <span>* param fixed $data 参数可以是除了对象以外的所有数据类型,比如:字符串,数组,jason等 </span><span>4</span> <span>*/</span> <span>5</span> <span>function</span> console(<span>$data</span><span>){ </span><span>6</span> <span>$stdout</span> = <span>fopen</span>('php://stdout', 'w'<span>); </span><span>7</span> <span>fwrite</span>(<span>$stdout</span>,json_encode(<span>$data</span>)."\n"); <span>//</span><span>为了打印出来的格式更加清晰,把所有数据都格式化成Json字符串</span> <span>8</span> <span>fclose</span>(<span>$stdout</span><span>); </span><span>9</span> }</span>
When you need to print the current debugging information after each request of the built-in Server: just call console() directly
For example:
Print all received GET or POST parameters:
console($_GET);
console($_POST);
Print string:
console("hello php console debug");
You no longer have to envy the console output of Python and Java, PHP now also has a console output function

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
