How do bugs in the PHP production environment gracefully debug?

Source: Internet
Author: User
Tags php error php error log
has been very vexed to a problem, some bugs can only be reproduced in the production environment, but I can not put a similar online echo $test;such as the code to debug, do not know if you have good experience to share.

Reply content:

has been very vexed to a problem, some bugs can only be reproduced in the production environment, but I can not put on the line similar echo $test; to the code to debug, do not know if you have good experience to share.

Using Socketlog

There is nothing wrong with hot commissioning of the production environment, but exposing the code logic and debugging data during hot commissioning is much more of a death. You must not cultivate this habit.

The correct approach is to use log tools such as Monolog to record the information you want to track. You can use methods such as extra querystring to constrain the behavior of logging.

Of course, you can also set up a/test class of test routes, and then use permissions control to prohibit visitors to enter ... Not elegant enough.

Trigger_error (Var_export ($var, true));
Then go to the PHP error log to check

You set a debug_cookie=true and then change your browser's COOKIE to debug it.
Then you put the debug output into the log file, you can view it. and will not affect the appearance of the external network.

Similar to the answer of the flash, but I'm using

error_log(var_export($data, true));

You can also modify the second parameter of the function to write the information you want to print to the specified file.

Best Answer: Php-console

Https://github.com/barbushin/php-console

My usual practice can be the following, of course, the conditions within the variable

if ( 'debug' == $_GET['status'] ) {    echo $test;}

This is a bit difficult. It's a good idea upstairs, and it's useless.

Like the first floor said the use of socketlog,xdebug,xhprof are good.

Use Docker to build an environment that enables local development debugging to have an environment that is the same as the server and a test database created with a backup of the production environment database during debugging

Chromephp::log ();

I wrote a log record of the class, in the need to debug the place to add the log code, you can

Simple debug output on the line, you can output the information to the file bar.

  • Related Article

    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.