In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to debug PhpStorm code, many people may not know much about it. In order to make you understand better, the editor summarizes the following content for you. I hope you can get something according to this article.
Most of the previous tutorials focus on how to improve the daily coding efficiency of PhpStorm, whether it is code navigation, plug-ins, keyboard shortcuts or code templates, code refactoring, all around efficiency. Next, the Academy will introduce you to topics other than efficiency, such as debugging, testing, and coding styles.
First of all, let's look at debugging.
In the PHP ecosystem, the most famous debugging tool is Xdebug:
Xdebug
So, next, let's take Xdebug as an example to demonstrate how to debug PHP code in PhpStorm.
Install and configure the Xdebug extension
Before you use Xdebug to debug your code, install the corresponding PHP extension.
Taking the Mac system as an example, we can use the php-m command in the terminal window to see if the Xdebug extension has been installed:
You can see "Xdebug" in the Zend Mdoules list to indicate that the installation was successful. If it is not already installed, you can refer to the Xdebug official documentation for installation.
In addition, you also need to carefully configure Xdebug through the configuration file. You can view the path of the PHP configuration file through the php-- ini command:
Here, we configure Xdebug in / usr/local/etc/php/7.4/php.ini as follows (of course, you can choose to create a new ext-xdebug.ini under the / usr/local/etc/php/7.4/conf.d directory to configure Xdebug separately, and PHP will automatically load the corresponding configuration file):
[XDebug]
Zend_extension= "xdebug.so"
Xdebug.remote_enable=1
Xdebug.remote_host=localhost
Xdebug.remote_port=9001
Xdebug.remote_autostart=1
Xdebug.profiler_enable=1
Xdebug.profiler_output_dir= "/ tmp"
Xdebug.idekey=PHPSTORM
Here we enable remote monitoring (including IP address and port settings), script analysis, and setting idekey to PHPSTORM. For details and meaning of debugging and analysis configuration items, please refer to the official debugging settings and script analysis documents provided by Xdebug.
After completing the above preparations, you can create a new index.php in any empty directory and write the following PHP script in it:
Then run php-S localhost:9000 to start the PHP built-in HTTP server, and visit http://localhost:9000 in the browser to see if the Xdebug extension configuration in PHP takes effect:
Configure the PHP CLI interpreter
Next, we can debug the PHP code through Xdebug in PhpStorm.
Before starting code debugging, configure the PHP CLI interpreter in Preferences | Languages & Frameworks | PHP:
If the current CLI Interpreter column in your PhpStorm is displayed, you can click on the right side. "Button add:
Note: you can also see here that the corresponding Debugger extension is Xdebug version 2.9.6. If the corresponding Xdebug extension information is not detected here, it means that this version of PHP does not install this extension. You need to refer to the installation and configuration steps above.
Enter the name of the CLI interpreter in the Name box and the path to the current system PHP binary file in the PHP executable box. If you don't know, you can run the which php command in the terminal window to view it.
Debug PHP CLI script code
Next, let's take a look at debugging a native PHP CLI script code. Let's start by writing a test code called multi.php, which prints the 99 multiplication table:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.