Php line by line debugging

Is there a tool out there that allows debugging of PHP applications line by line? Like how it’s done in perl or .net?

As normal Perl code, this is the same as loading Devel::MyDebugger with use.,It comes with its own terminal-based debugger named ebug. It’s a bit of an odd name until you realize how you call it. The missing d in the name comes from Perl’s -d switch.,I don’t really have to use print because I can do the same thing with warn, which sends its output to standard error:,Although I’ve called print the best debugger in the world, I actually use a disguised form in the carp function from the Carp module, part of the standard Perl distribution. It’s like warn, but it reports the filename and line number from the bit of code that called the subroutine:

$ perl -Mstrict -Mwarnings program

Answer by Elyse Craig

Xdebug’s Profiler is a powerful tool that gives you the ability to analyse your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler also collects information about how much memory is being used, and which functions and methods increase memory usage.,Xdebug’s built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind.,Enable this functionality by setting the value to a absolute path. Make sure that the system user that PHP runs at (such as www-data if you are running with Apache) can create and write to the file., The function returns an array of all the compile flags that were enabled when running ./configure as part of Xdebug’s compilation process.

The log file will include any attempt that Xdebug makes to connect to an IDE:

[2693358] Log opened at 2020-09-02 07:19:09.616195 [2693358] [Step Debug] INFO: Connecting to configured address/port: localhost:9003. [2693358] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-( [2693358] [Profiler] ERR: File '/foo/cachegrind.out.2693358' could not be opened. [2693358] [Profiler] WARN: /foo: No such file or directory [2693358] [Tracing] ERR: File '/foo/trace.1485761369' could not be opened. [2693358] [Tracing] WARN: /foo: No such file or directory [2693358] Log closed at 2020-09-02 07:19:09.617510 
INFO: Connecting to configured address/port: localhost:9003. ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-( 
ERR: File '/foo/cachegrind.out.2693358' could not be opened. WARN: /foo: No such file or directory 
ERR: File '/foo/trace.1485761369' could not be opened. WARN: /foo: No such file or directory 

The debugging log can also log the communication between Xdebug and an IDE. This communication is in XML, and starts with the

Читайте также:  Javascript ok cancel message

Many Linux distributions now use systemd, which implements private tmp directories. This means that when PHP is run through a web server or as PHP-FPM, the /tmp directory is prefixed with something akin to:

/tmp/systemd-private-ea3cfa882b4e478993e1994033fc5feb-apache.service-FfWZRg 

Источник

Cannot debug php line by line in vscode

My server I’m using live server: Things I’ve tried: deleting and reinstalling both live servers quitting VS code made sure Live Server was turned on in VS code. Question: I’ve installed the extension on VS code and on google chrome, and configure them to enable live reload but live reload is not working.

Cannot debug php line by line in vscode

Given this setting in my vscode

< // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ < "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9003, "hostname":"::1", "pathMappings": < "/var/www/html/": "$/item-street" > >, < "name": "Launch currently open script", "type": "php", "request": "launch", "program": "$", "cwd": "$", "hostname": "::1", "port": 9003 > ] > 
zend_extension=xdebug.so xdebug.mode=debug xdebug.client_port=9003 xdebug.discover_client_host=1 

This xdebug configuration is located in /etc/php/8.0/mods-available/ in WSL2 Ubuntu-20.04 following the setting here

But adding break point on php code and pressing f5 , and visit the local php project in chrome just nothing happen.

I did also read the following

Setting up VSCode with xdebug: pathmapping

VSCode — XDebug connected to client but break points does not work

but seems doesn’t work to my case.

previously its fine but now it’s not

Just found an answer myself. On VSCode click the remote explorer not sure if this is really part of it and next install PHP debugger extension on Google Chrome.

Put a break point on PHP file, click PHP debugger on chrome, press f5 on VSCode, and it worked.

My initial statement works, but not really the answer. The actual answer is the https://github.com/felixfbecker/vscode-php-debug only support port:9000 or it’s just xdebug the only support port 9000.

How to configure vscode for php Code Example, Get code examples like «how to configure vscode for php» instantly right from your google search results with the Grepper Chrome Extension.

How do we get VSCode with XDebug to ignore known code issues?

Environment : Visual Studio Code, PHP 7.4, XDebug, WordPress site in Local by Flywheel, all on Windows 10. This is all working. The issue us that there is a trivial unhandled exception that always occurs in WordPress which is ignored in normal processing. But the exception reports clutter my plugin debugging. So I’d like to eliminate XDebug reporting of just one small section of WP core code.

Читайте также:  Call functions in function javascript

In index.php I’ve added the following to no effect:

xdebug_set_filter( XDEBUG_FILTER_STACK, XDEBUG_PATH_INCLUDE, [__DIR__ . "/wp-content/plugins/myplugin/"] ); 

I added similar code to wp-load.php, also no effect:

$path=__DIR__ . "\\wp-content\\plugins\\myplugin"; xdebug_set_filter( XDEBUG_FILTER_STACK, XDEBUG_PATH_INCLUDE, [$path] ); 

In the WP Core code (wp-db.php) I have bracketed the exception-throwing code with this:

xdebug_disable(); . xdebug_enable(); 

One thing that’s confusing about this is that the VS Code intellisense doesn’t recognize the xdebug functions, and yet using xdebug_break(); does cause XDebug to break.

  • Question 1: What do we do to get VSCode/PHP/Intelephense to recognize XDebug functions?

Yes, the UI shows error «Call to undefined function xdebug_disable()». So in addition to just getting IDE support:

  • Question 2: What do we do to get a VSCode project/workspace to recognize the php_xdebug.dll features?

(More specifically for this environment this is «C:\Users\me\AppData\Roaming\Local\lightning-services\php-7.4.1+16\bin\win64\ext\php_xdebug-3.0.4-7.4-vc15-nts-x86_64.dll»)

For this specific challenge:

  • Question 3: What is the proper technique to get XDebug to avoid a specific code block?

Do we bracket with enable/disable?
Do we use xdebug_set_filter to focus on just the namespace or folders of interest?
Do we bracket with something like this? :

xdebug_start_error_collection(); . xdebug_stop_error_collection(); xdebug_get_collected_errors(true); 

Finally, because I want to learn how this works and not just get answers for this specific challenge:

  • Question 4: Where can we find documentation about how to use these functions to solve actual problems, outside of the great syntax docs provided at https://xdebug.org/docs/develop ?

Most of your questions seem to come from knowing about Xdebug 2, but using Xdebug 3 which has a changed set of configuration settings and functions, which are documented in the upgrade guide.

Question 1: Call to undefined function xdebug_disable()

This is because Xdebug 3 does no longer have this function, see: https://xdebug.org/docs/upgrade_guide#Changes-to-Functions

Question 2: What do we do to get a VSCode project/workspace to recognize the php_xdebug.dll features?

It already does, because xdebug_break() works for you. You’re just using functions of the old version.

Question 3: What is the proper technique to get XDebug to avoid a specific code block?

Xdebug can’t do that for debugging. It’s usually built-into IDEs. PhpStorm for example has a way to exclude directories. I am not 100% about the VS Code Plugin, but they’ve recently made a change to not have default exception filters on by default, which might as well solve your problem.

Do we bracket with enable/disable?

No. That function no longer exists, but it’s only effect was showing, or not showing Xdebug’s orange errors. It never had any effect on debugging.

Do we use xdebug_set_filter to focus on just the namespace or folders of interest?

The filter has two categories, one for stack traces (with XDEBUG_FILTER_STACK ) and one for code coverage (with XDEBUG_FILTER_COVERAGE ). There is none for debugging yet, bug I’ve created a feature request to get this supported (from Xdebug 3.1).

Do we bracket with something like this? :

xdebug_start_error_collection(); . xdebug_stop_error_collection(); xdebug_get_collected_errors(true); 

That’s only for collecting errors. It doesn’t stop errors from occurring.

Question 4: Where can we find documentation about how to use these functions to solve actual problems, outside of the great syntax docs provided at https://xdebug.org/docs/develop ?

I would start with the upgrade guide, and also have a look at the recently rewritten step debugger documentation. I’ve also recently starting videos for specific things to the documentation, a few on step debugging, and there a full list as well.

Читайте также:  Spark web framework java

I am still adding to these videos, and will also be adding non-video content. If you want to suggest specific ideas for these videos, please send in a documentation issue in Xdebug’s bug tracker.

Php debugger vscode Code Example, Get code examples like «php debugger vscode» instantly right from your google search results with the Grepper Chrome Extension.

Live reload not working for php files in vs code

I’ve installed the live server extension on VS code and on google chrome, and configure them to enable live reload but live reload is not working. It was working a few hours ago but now I can’t get it to work.

My server I’m using

live server:

  • deleting and reinstalling both live servers
  • quitting VS code
  • made sure Live Server was turned on in VS code.

Make sure you are not running another localhost website somewhere, live server can only reload one website at a time.

In my case all below steps helped:

-change settings in VS Code. If you go to Settings, search for these options and set them as below:

Live Server Settings: Custom Browser: chrome (I use chrome, you can choose yours of course) Full Reload: yes, you should mark it Port: 0 Use Web Ext: unmark it Wait: 3

Settings: autosave: afterDelay

-check if your HTML file name is correct (without special signs etc) and if there is utf-8 in -I also installed extension in my Chrome browser («LiveReload»)- you can download it in GoogleStore.

Save all changes, reopen chrome and VsCode and check if it works.

How to enable check syntax PHP in visual studio code?, There are no errors in your code example. From the manual: As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement. The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a …

Источник

Оцените статью