Those of you who have used static languages such as Java and C# to debug code often make a breakpoint and debug it easily, whereas PHPer debugging code often does
echo $a;exit;Copy the code
Very inconvenient, some students sometimes finish the breakpoint without deleting the commit, which causes a lot of trouble, is there a way to debug more elegant? Of course there is, here uses a PHP module xdebug, XDEBUG installation tutorial, using it for HP code debugging, can effectively reduce the workload and BUG debugging time, especially in some complex programs, just by looking can not find the problem
Xdebug is an open source PHP program debugger (that is, a Debug tool) that can be used to trace, Debug, and analyze the health of PHP programs.
If you have an integrated environment like PHPStudy, you don’t need to install it yourself.
I’m going to set the lower port number, whatever I like, and I’m going to set 9001
Check phpInfo, do a search, and you’ll have the XDebug module
Next open phpStorm, CTRL + Alt + S to open Settings
Go to debug Settings and change the port number to the one you set earlier.
Open Servers, press + to create a new one, use whatever name you want, Host the domain you want to Debug (for example, localhost, I used a virtual domain name here), and use the default port number 80
Then you have an Edit Configurations in the upper right corner, click open
Click the plus sign to add a PHP Web Page
If I want to debug an interface that places an order, I will fill it in and click Validate as indicated by the arrow
The first option is to debug local, and the second option is to debug remote, so I’m not going to confuse you with remote
The first field is your project directory, and since I’m using tinkPHP framework, I point it to the public directory of the project directory
The second fill in their own domain name, here the editor automatically help fill in
Click the Validate button and PHPStorm will check if the configuration is correct. If there are any errors, please follow the instructions
Finally, clicking the bug in the upper right corner will automatically open the browser for debugging. If the phone next to the bug turns green, it means that port 9001 is being monitored
Phpstorm will automatically open the Debug console, click the arrow to automatically next, and click the red dot on the left to break the spot
What if you want to use Postman?
I’m going to take this parameter
Add the key-vlue pair to the postman parameter and click Send to start debugging automatically (Postman will continue to send until the breakpoint debugging is complete)
Brief description of the Debug console
- The left side can be broken points that stop code execution when it reaches a breakpoint
This button, when clicked, executes a line of code, but when it encounters a function it executes the entire function
This button also executes a line of code that can be executed inside the function
Skip to the next breakpoint
The first page clearly shows all the variables
The second page can print variables and even execute object function methods (thief useful)
The third page is to view the output
The problem summary
- Breakpoint debugging is when Apache automatically disconnects after the PHP script times out and returns a 500 error
Add it in the http.conf file of Apache
FcgidIOTimeout 6000Copy the code
Phpstorm uses Xdebug to debug code
For more PHP content visit:
Tencent T3-T4 standard boutique PHP architect tutorial directory directory, as long as you finish the guarantee salary rise a step (continue to update)
I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, YII2, Redis, Swoole, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc.