Use of Php+xdebug

Source: Internet
Author: User
Tags fpm php script

(a) Set up PHP: Let the CGI and CLI use different configuration files:

HTTP request with php.ini, command line script with Php-cli.ini:

sudo cp/usr/local/php/etc/php.ini/usr/local/php/etc/php-cli.ini


The HTTP request only triggers debug with a cookie:

Set XDEBUG, only passively trigger debug (debug is only triggered for requests with cookie:xdebug_session= your Idekey):

Edit PHP.ini, add or modify the following:

zend_extension =  "/usr/local/php/modules/xdebug.so" xdebug.default_enable=onxdebug.collect_params= Onxdebug.collect_vars=onxdebug.collect_return=onxdebug.show_local_vars=1xdebug.remote_handler= dbgpxdebug.remote_enable=1xdebug.remote_host=172.16.2.69                    #  installation of Ip;xdebug.remote_connect_back of Phpstorm machines =1                     #  if enabled and writes  1 here, it will automatically    connect request source IP when you start debugging. This configuration overrides the IP  remote_host  settings. It is not recommended to turn this on (in case there is a machine that starts up 360 security defender = =) to access your virtual machine. 360 Security Defender = = Firewall software to open the network protection, foreign TCP connection   will be suspended for a long time, causing Php-fpm worker process suspended animation). xdebug.remote_port=9001                           #  consistency with phpstorm settings Xdebug.remote_ Autostart=offxdebug.remote_log=/dev/nullxdebug. auto_trace=offxdebug.show_exception_trace=0 

Restart PHP-FPM after the change.


Debug is triggered automatically when the command line executes the script:

When the command line executes the script, debug is triggered if Phpstorm initiates debug:

Edit Php-cli.ini, add or modify the following:

Zend_extension = "/usr/local/php/modules/xdebug.so" xdebug.default_enable=onxdebug.collect_params= Onxdebug.collect_vars=onxdebug.collect_return=onxdebug.show_local_vars=1xdebug.remote_handler=                          dbgpxdebug.remote_enable=1xdebug.remote_host=172.16.2.69 # Installation of the Phpstorm machine ipxdebug.remote_port=9001 # stay consistent with the Phpstorm settings xdebug.remote_autostart=onxdebug.idekey= your IDEKEY-CLI # better be unique to yourself, not with Others repeat Xdebug.remote_log=/dev/nullxdebug.auto_trace=offxdebug.show_exception_trace=0
(ii) Setting up Phpstorm and browsers:1) Set Phpstorm debug port, etc., it is also recommended to add Zend, smarty, etc. to skipped-paths:

650) this.width=650; "class=" Confluence-embedded-image "title=" platform Group > Xdebug+phpstorm Configuration Recommendations > phpstorm5.jpg "src=" Http://192.168.1.121:8095/download/attachments/18088373/phpstorm5.jpg?version=2&modificationDate= 1419509105000&api=v2 "style=" border:1px solid transparent; alt= "Phpstorm5.jpg?version=2&modificationdate" />

 2) Go to Run, Edit configurations, add server:

650) this.width=650; "class=" Confluence-embedded-image "title=" platform Group > Xdebug+phpstorm Configuration Recommendations > Phpstorm.jpg "src=" http://192.168.1.121:8095/download/attachments/18088373/phpstorm.jpg?version=1& Modificationdate=1419502855000&api=v2 "style=" border:1px solid transparent; alt= phpstorm.jpg?version=1& Modificationdate= "/>

3) Add Debug Configuration:

650) this.width=650; "class=" Confluence-embedded-image "title=" platform Group > Xdebug+phpstorm Configuration Recommendations > phpstorm3.jpg "src=" Http://192.168.1.121:8095/download/attachments/18088373/phpstorm3.jpg?version=2&modificationDate= 1419504056000&api=v2 "style=" border:1px solid transparent; alt= "Phpstorm3.jpg?version=2&modificationdate" />

4) similar to the third step, continue to add "Ide key" for "Your Idekey-cs", "Your Idekey-cs-cs", "Your Idekey-cs-cs-cs", "Your Idekey-cs-cs-cs-cs" and "Your IDEKEY-CLI "Debug Configuration,

Used to debug the Curl service-side code ("CS" means Curl Server-side, a "-cs" suffix means to debug the service side of the first layer of curl, two means to debug the second layer ....) )。

It is recommended to add 3 or more similar configurations.

650) this.width=650; "class=" Confluence-embedded-image "title=" platform Group > Xdebug+phpstorm Configuration Recommendations > phpstorm7.jpg "src=" Http://192.168.1.121:8095/download/attachments/18088373/phpstorm7.jpg?version=1&modificationDate= 1419823119000&api=v2 "style=" border:1px solid transparent; alt= "Phpstorm7.jpg?version=1&modificationdate" />

5) Start debug: Menu Run, Debug ...., select Debug configuration name. Multiple configurations can be enabled at the same time to debug multiple layers of HTTP requests at the same time.

Three Debug configurations enabled: Devbox, Devbox-cs-cs, Devbox-cs-cs-cs, Devbox-cs not enabled,

So the Web request is debugged, the second layer of curl, and the third layer of curl does not debug the first layer of curl.

Start the DEVBOX-CLI configuration to debug the command-line PHP script executed on the Devbox machine.

650) this.width=650; "class=" Confluence-embedded-image "title=" platform Group > Xdebug+phpstorm Configuration Recommendations > phpstorm6.jpg "src=" Http://192.168.1.121:8095/download/attachments/18088373/phpstorm6.jpg?version=1&modificationDate= 1419561744000&api=v2 "style=" border:1px solid transparent; alt= "Phpstorm6.jpg?version=1&modificationdate" />

6) After modifying this link, open from the browser:

http://192.168.100. Your virtual machine ip:8072/setcookie.php?idekey= your Idekey

this request will add cookie:xdebug_session= your idekey,domain= virtual machine full IP (without port) to the browser and set the growth time to not be period. Subsequent access to the virtual machine triggers debugging.

(c) Anti-debug timeout:

# Php*.ini (/usr/local/php/etc/php*.ini): max_execution_time=7200 # php-fpm.conf (/usr/local/php/etc/php-fpm.conf): request_terminate_timeout = 0 # FPM does not impose a time limit.   # Nginx (/usr/local/nginx/conf/nginx.conf) Add or modify these two on the HTTP side: Fastcgi_connect_timeout 7200s; # because PHP-FPM may be debugged to block fastcgi_read_timeout 7200s;
(iv) Other configuration recommendations:
  • Linux/mac in the Phpstorm installation directory under the bin/phpstorm.sh top add a row of ulimit-s 256 can save about 600M of physical memory (if you run the PHP interpreter in "Phpstorm internal" encounter problems, you can try Ulimit- s 512, not measured).

  • It is recommended to open 8 or more PHP-FPM worker processes, and if n layer curl is at least n+1, the request will be deadlocked.

  • If you encounter strange problems such as a breakpoint being ignored, not step-in, Set-value, and so on, you can disable the Eaccelerator test.

  • When the page has not been loaded for a long time, it is most likely because your notebook prohibits remote connections (360 security defender = = Network firewall software will prohibit incoming TCP connections), you can check whether the connection is unblocked from the virtual machine:

    One-box-test-6 Devbox $ telnet your laptop IP 9001 # Log in to virtual machine execution



This article is from the "I Believe" blog, please be sure to keep this source http://mrcelite.blog.51cto.com/2977858/1612320

Use of Php+xdebug

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.