Home >Backend Development >PHP Tutorial >PHP production environment uses php://stdout for safe and efficient debugging
There are many ways to debug PHP during development. For production environment debugging, both performance and security must be considered. The following are common methods and their disadvantages:
1. Write a log. Use fopen to open a file and write a log. This method is simple and efficient, but when multiple users access it at the same time, it will cause competition problems, consume disk IO, and the file size is not easy to control;
2. Write the database. This method solves the competition problem, but increases the burden on the database. ;
When I was looking at the new features of the new version of php, php://stdout is built-in support from version 5.6. This is a memory object, and the output is printed directly on the server command line, which is completely invisible to the user;
The following is My test code
echo "Hello World!";
$fd = fopen('php://stdout', 'w');
if ($fd) {
fwrite($fd, "7777888");
fwrite($fd, "n" );
fclose($fd);
7777888
7777888
7777888
The above introduces the use of php://stdout for safe and efficient debugging in the PHP production environment, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.