Better Debugging with Xdebug ๐Ÿ”— **Source:** [Better Debugging with Xdebug](https://www.youtube.com/watch?v=w53joR83jzU) > [!note]+ Document Notes > tags: [xdebug, php-debugging, development-tools] > author: Derick Rethans > source: YouTube > reference: https://www.youtube.com/watch?v=w53joR83jzU > date created: 2024-12-19 11:52 > > # ๐Ÿท๏ธ Title: Better Debugging with Xdebug > <!-- deep-read:sections start --> ## ๐Ÿงฐ Action Inbox - [H1] Set up xdebug_info() for debugging configuration issues โ€” replace phpinfo() in development #debugging - [H2] Create path mapping files to solve Docker/remote debugging โ€” avoid IDE configuration complexity #docker - [H3] Use xdebug_notify() for output-free variable inspection โ€” cleaner than var_dump() #debugging ## ๐Ÿงญ Table of Contents - [๐Ÿ“ Summary](#-summary) - [๐Ÿ“– Main Content](#-main-content) - [๐Ÿ—’๏ธ Notes](#๏ธ-notes) - [๐Ÿ“š References](#-references) - [๐Ÿ—ฃ๏ธ Paraphrase](#๏ธ-paraphrase) - [๐Ÿ“ฐ Newsletter](#-newsletter) - [โœ… Action Items](#-action-items) - [๐Ÿงช Hypotheses](#-hypotheses) - [๐Ÿ“Š Methodology](#-methodology) - [โ“ Questions](#-questions) - [๐Ÿ”ฎ Future Research](#-future-research) - [๐Ÿ’ก Implications](#-implications) - [๐Ÿง  Learning Styles Assessment](#-learning-styles-assessment) - [๐Ÿ“Š Accessibility Assessment](#-accessibility-assessment) - [๐ŸŒ DEIB Assessment](#-deib-assessment) - [โœ… Logical Validity](#-logical-validity) - [๐Ÿ›ก๏ธ DARVO Analysis](#-darvo-analysis) - [๐ŸŽฏ Conclusion](#-conclusion) ### ๐Ÿ”— References - [Xdebug Documentation](https://xdebug.org/docs/) - [PHP Foundation](https://thephp.foundation/) ## ๐Ÿ“ Summary - **What happened**: Derick Rethans demonstrated new Xdebug features for better PHP debugging, particularly for Drupal development - **Why it matters**: Many developers struggle with debugging containerized applications and complex frameworks like Drupal - **Key stakeholders**: PHP developers, Drupal developers, DevOps engineers working with containerized environments - **Risks and tradeoffs**: New features are experimental and require configuration; logging can generate megabytes of data - **Bottom line**: Xdebug 3.4+ introduces path mapping, conditional breakpoints, return value inspection, and control sockets for more effective debugging ## ๐Ÿ“– Main Content Derick Rethans, lead developer of Xdebug and PHP Foundation member, presented advanced debugging techniques focusing on containerized PHP development. The session addressed common debugging challenges when using Docker, DDev, and remote development environments where traditional IDE-to-PHP connections fail due to path mismatches and network constraints. Key innovations include xdebug_info() as a diagnostic tool similar to phpinfo(), native path mapping files that eliminate IDE configuration complexity, and xdebug_notify() for clean variable inspection without disrupting page output. The presentation demonstrated these features using a Drupal project running in DDev, showing how to diagnose connection issues and set up proper debugging workflows. Advanced features covered include conditional breakpoints for filtering specific code execution, return value inspection to see function outputs without variable assignment, and control sockets for debugging long-running processes. Future developments include time travel debugging for post-mortem analysis and Xdebug Cloud for circumventing network restrictions. ## ๐Ÿ—’๏ธ Notes #### โฑ๏ธ [00:00](https://www.youtube.com/watch?v=w53joR83jzU?t=0) โ€” [H1] Introduction and Speaker Background - Key idea: Derick Rethans introduces himself as Xdebug maintainer and PHP Foundation developer - Evidence: "I'm Derek. I'm European... I'm the ultra fix book. been working on that for about 23 years" #### โฑ๏ธ [03:45](https://www.youtube.com/watch?v=w53joR83jzU?t=225) โ€” [H1] Common Debugging Problem: Connection Failures - Key idea: Breakpoints often fail to work in containerized environments due to path mismatches - Evidence: "Nothing happened, right? Why would that be?" #### โฑ๏ธ [05:12](https://www.youtube.com/watch?v=w53joR83jzU?t=312) โ€” [H2] Introducing xdebug_info() Function - Key idea: xdebug_info() provides diagnostic information similar to phpinfo() but for debugging configuration - Evidence: "Now XDbook info is the same thing. Now why is this useful?" #### โฑ๏ธ [07:30](https://www.youtube.com/watch?v=w53joR83jzU?t=450) โ€” [H2] Diagnosing Connection Issues - Key idea: xdebug_info() shows specific error messages with links to documentation for fixes - Evidence: "It says could not connect to the host discovered through HTTP headers" #### โฑ๏ธ [09:18](https://www.youtube.com/watch?v=w53joR83jzU?t=558) โ€” [H1] Path Mapping Solution - Key idea: New path mapping files eliminate need for IDE configuration in containerized environments - Evidence: "I've created the XDA directory and I put a file in there called path mapping map" #### โฑ๏ธ [12:45](https://www.youtube.com/watch?v=w53joR83jzU?t=765) โ€” [H2] Skip Vendor Directories - Key idea: Path mappings can skip debugging vendor/composer directories to reduce noise - Evidence: "How often do you need to debug anything in vendor/composer? Almost never, right?" #### โฑ๏ธ [16:20](https://www.youtube.com/watch?v=w53joR83jzU?t=980) โ€” [H2] Conditional Breakpoints - Key idea: Breakpoints can include conditions to break only when specific criteria are met - Evidence: "This expression is now being evaluated when this break point hits" #### โฑ๏ธ [19:35](https://www.youtube.com/watch?v=w53joR83jzU?t=1175) โ€” [H2] Smart Breakpoint Placement - Key idea: Xdebug automatically adjusts breakpoints from empty lines to nearby executable code - Evidence: "It didn't stop on the line where it's at a break point, but it stops in the next one" #### โฑ๏ธ [21:10](https://www.youtube.com/watch?v=w53joR83jzU?t=1270) โ€” [H2] xdebug_notify() for Clean Output - Key idea: xdebug_notify() sends variable dumps to IDE without affecting page output - Evidence: "The notification doesn't go through the output... but instead the information gets sent over the debugging protocol" #### โฑ๏ธ [25:00](https://www.youtube.com/watch?v=w53joR83jzU?t=1500) โ€” [H2] Comprehensive Logging - Key idea: Detailed log files show complete debugging protocol communication for troubleshooting - Evidence: "For one request you easily get megabytes of information" #### โฑ๏ธ [28:15](https://www.youtube.com/watch?v=w53joR83jzU?t=1695) โ€” [H2] Return Value Inspection - Key idea: New feature allows inspecting function return values without variable assignment - Evidence: "You can inspect the return value which I think is a nice thing" #### โฑ๏ธ [31:40](https://www.youtube.com/watch?v=w53joR83jzU?t=1900) โ€” [H2] Exception Breaking - Key idea: Debugger can break on all exceptions, notices, and warnings automatically - Evidence: "Break on all the exceptions, all the notices and warnings" #### โฑ๏ธ [35:20](https://www.youtube.com/watch?v=w53joR83jzU?t=2120) โ€” [H1] Control Sockets for Long-Running Scripts - Key idea: New xdebug_ps tool allows debugging already running PHP processes - Evidence: "How do I debug this? You can't really, right? because XDBook only initiates a connection to the ID when the script starts" #### โฑ๏ธ [41:50](https://www.youtube.com/watch?v=w53joR83jzU?t=2510) โ€” [H1] Future Features: Time Travel Debugging - Key idea: Planned feature will record entire request execution for post-mortem debugging - Evidence: "Record the whole request including all intermediate steps variable assignments function calls dump that into a file" #### โฑ๏ธ [44:30](https://www.youtube.com/watch?v=w53joR83jzU?t=2670) โ€” [H2] Xdebug Cloud for Network Issues - Key idea: Cloud service routes debugging connections around firewall and network restrictions - Evidence: "XDbook cloud... is basically a way of rooting around these networking issues" ## ๐Ÿ“š References - [Xdebug Official Documentation](https://xdebug.org/docs/) - [PHP Foundation](https://thephp.foundation/) - [DDev Documentation](https://ddev.readthedocs.io/) ## ๐Ÿ—ฃ๏ธ Paraphrase - Xdebug 3.4+ introduces xdebug_info() as a diagnostic tool that helps identify why debugging connections fail, particularly in containerized environments - Path mapping files can be created directly in projects to handle Docker/remote debugging without complex IDE configuration - New debugging features include conditional breakpoints, return value inspection, clean variable output via xdebug_notify(), and control sockets for long-running processes ## ๐Ÿ“ฐ Newsletter ๐Ÿš€ **Enhanced PHP Debugging with Xdebug 3.4+** Debugging containerized PHP applications just got easier! Derick Rethans showcased powerful new Xdebug features that solve common debugging headaches, especially for Docker and DDev users. **Key highlights:** - **xdebug_info()**: Like phpinfo() but for debugging - instantly diagnose connection issues - **Native path mapping**: Create simple mapping files in your project root instead of complex IDE configs - **xdebug_notify()**: Clean variable inspection without breaking your page layout - **Control sockets**: Debug long-running scripts that are already in progress These improvements make debugging more accessible and reliable, particularly for teams working with containerized development environments. **Resources:** [Xdebug Docs](https://xdebug.org/docs/), [PHP Foundation](https://thephp.foundation/), [DDev](https://ddev.readthedocs.io/) ## โœ… Action Items #### WordPress - Core: Investigate Xdebug 3.4+ adoption for core development workflows - Core Performance: Use conditional breakpoints for performance bottleneck identification - Playground: Implement path mapping for WordPress Playground debugging scenarios - Community: Create debugging workshops using new Xdebug features - Documentation: Document best practices for containerized WordPress debugging ## ๐Ÿงช Hypotheses - Path mapping files will reduce debugging setup complexity for containerized WordPress development - xdebug_notify() will improve developer experience by eliminating output interference during debugging - Control sockets will enable debugging of long-running WordPress processes like imports and migrations - Time travel debugging (when available) will revolutionize post-mortem analysis of production issues ### ๐Ÿ“Š Methodology - Compare debugging setup time before/after path mapping implementation - Survey developer satisfaction with xdebug_notify() vs traditional var_dump() - Measure adoption rates of new Xdebug features in WordPress development teams ### โ“ Questions - How can WordPress core development benefit from conditional breakpoints during performance optimization? - What impact will time travel debugging have on production issue resolution workflows? - How can path mapping be standardized across WordPress development environments? ### ๐Ÿ”ฎ Future Research - Integration patterns for Xdebug Cloud in enterprise WordPress hosting environments - Performance impact analysis of comprehensive debug logging in development workflows - Best practices for debugging WordPress multisite installations using new Xdebug features ### ๐Ÿ’ก Implications - **Practice**: Simplified debugging setup reduces barriers to entry for WordPress development - **Policy**: Teams may need updated debugging standards incorporating new Xdebug features - **Security**: Enhanced debugging capabilities improve security issue investigation processes - **Education**: Training materials need updates to cover modern debugging workflows - **Funding**: Investment in debugging infrastructure becomes more cost-effective with these improvements ### ๐Ÿง  Learning Styles Assessment Reading level estimate: Grade 12-14 (technical presentation with specialized vocabulary) #### ๐Ÿ‘€ Visual learners - Present: Live code demonstrations, IDE interface examples, breakpoint visualizations - Improve: Debugging workflow diagrams, network connection visualizations #### ๐Ÿ”Š Aural learners - Present: Live presentation format with detailed explanations - Improve: Audio summary of key debugging concepts and workflows #### ๐Ÿ—ฃ๏ธ Verbal learners - Present: Technical terminology explained, analogies for debugging concepts - Improve: Glossary of debugging terms, comparison tables #### ๐Ÿงฉ Kinesthetic learners - Present: Live coding demonstrations, hands-on debugging examples - Improve: Step-by-step debugging checklists, interactive tutorials #### ๐Ÿง  Logical learners - Present: Systematic progression through debugging features, cause-effect relationships - Improve: Decision trees for debugging scenarios, troubleshooting flowcharts #### ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Social learners - Present: Q&A session, community interaction - Improve: Peer debugging exercises, collaborative troubleshooting guides #### ๐Ÿง˜โ€โ™€๏ธ Solitary learners - Present: Self-paced demonstration viewing, individual practice opportunities - Improve: Solo debugging challenges, personal reflection prompts #### ๐ŸŒฟ Naturalistic learners - Present: Real-world debugging scenarios, practical applications - Improve: Debugging ecosystem analogies, environmental considerations ### ๐Ÿ“Š Accessibility Assessment #### Screen reader semantics - Present: Clear heading structure in presentation, descriptive code examples - Improve: Alt text for code screenshots, ARIA labels for complex demonstrations #### Keyboard navigation - Present: Standard presentation navigation - Improve: Keyboard shortcuts for debugging workflows, accessible IDE configurations #### Contrast and readability - Present: High contrast code editor themes demonstrated - Improve: Ensure all code examples meet contrast requirements #### Text resizing and reflow - Present: Scalable presentation format - Improve: Responsive code examples, adjustable font sizes #### Media and captions - Present: Live presentation format - Improve: Automated captions for technical terminology, transcript availability #### Forms and interactions - Present: Interactive Q&A format - Improve: Accessible feedback mechanisms, keyboard-only interaction support ### ๐ŸŒ DEIB Assessment #### Cultural breadth - Present: International speaker perspective, global developer community focus - Improve: Multi-language debugging examples, diverse development environment scenarios #### Inclusive language - Present: Technical but approachable language, defined jargon - Improve: Plain language summaries, reduced idioms and cultural references #### Neurodiversity support - Present: Structured presentation flow, clear topic transitions - Improve: Content warnings for flashing screens, consistent visual patterns #### Representation - Present: Focus on technical content over personal characteristics - Improve: Diverse debugging scenarios, inclusive example contexts #### Psychological safety - Present: Encourages questions, acknowledges complexity - Improve: Explicit welcome for all skill levels, mistake normalization ### โœ… Logical Validity #### Strong reasoning - Deductive strength: Clear problem-solution patterns throughout presentation - Inductive strength: Multiple examples supporting general debugging principles - Causal reasoning: Demonstrates clear cause-effect relationships in debugging failures - Analogical strength: Effective comparisons between debugging tools and familiar concepts #### Fallacies - Appeal to authority: Minimal - expertise demonstrated through technical knowledge rather than claimed - False dilemma: None identified - presenter acknowledges multiple solutions and approaches #### Tone of voice - Overall tone: Technical but approachable, educational, encouraging experimentation ### ๐Ÿ›ก๏ธ DARVO Analysis - Deny: No concerning denial patterns identified - Attack: No attacks on critics or alternative approaches - Reverse victim/offender: Not applicable to technical presentation - Emotional cues and rhetoric: Positive, encouraging tone focused on problem-solving ## ๐ŸŽฏ Conclusion Xdebug 3.4+ introduces significant improvements that address long-standing debugging challenges in containerized and remote development environments. The combination of diagnostic tools, simplified configuration, and advanced debugging features makes PHP debugging more accessible and effective for developers at all levels. Key practical next steps include updating development environment configurations to leverage path mapping, incorporating xdebug_notify() for cleaner debugging output, and exploring conditional breakpoints for more <!-- deep-read:sections end --> ## ๐Ÿ“บ Video ![](https://www.youtube.com/watch?v=w53joR83jzU) --- # ๐Ÿ“„ Full Transcript *Auto-generated from YouTube captions ยท timestamps roughly every 30 seconds ยท [watch on YouTube](https://www.youtube.com/watch?v=w53joR83jzU)* **[00:00]** Morning. >> Morning. >> I was wondering why my desk was so nicely mint green, but I now realize it's just the shine of the screen behind me and not the actual device. Anyway, good morning. Uh, hope you had a good day so far. I know it's a bit early. Feels early to me. Um, so I'll be giving a chat about what's the new things in XDbook. And maybe some of you might be using it for a while, some of you might not have been using it for a while. Uh, I hope that most of you will get something out of it regardless. **[00:32]** And so let's let's let me get straight into these things. So, hi, I'm Derek. I'm European. There's a specific reason why that's on the screen, but to find out, you have to talk to me later. Uh, I'm do most of my work for the PHP Foundation, an organization that is there to promote the PHP language. Um, and the intention is to get some companies to pay for some money so that they can then pay for people to work on the PHP language. And I'm I'm part of the people that do this then one of the **[01:03]** 10 developers that the PHP foundation hires. I don't actually end up doing so much PHP development work at the moment, but it's mostly all the server infrastructure behind it because that also needs doing and nobody volunteers for that kind of annoying stuff, right? I'm the ultra fix book. been working on that for about 23 years, give or take. I can't really quite remember. Um, I like maps, spee whiskey, irrelevant, but I thought I'd mention it. If you have any questions, the email usually works. Uh, but I don't put **[01:35]** it on the screen because I get too much email anyway. Uh, so master is the way to go. Last few people coming in here before I get u get going. There will be code on the slides and I will be demoing quite a lot. So I have prayed to the demo goss this morning but you never know whether that works or not. All right let's get going then. So XDbook info you have heard of PHP info right hopefully. Now XDbook info is the same thing. Now why is this useful? When setting up this **[02:05]** presentation or talking about it I got a message saying oh almost everybody uses DD to use to develop with Drupal. So I said well I should try that out then. Right. So I did after a bit of messing around uh I got that going or so I thought. So I got my Drupal Dup So I had to press reload. I got my Drupal site going. I don't actually know which one this is. It's some kind of demo one. >> I have to admit I know nothing about Drupal. Well, not very much. A little **[02:35]** bit more than I did last week. And I wanted to debug this right. So I have my browser. Sorry my IDE. I have like the the index info file and I set a breakpoint on like line 14. So in VS Code you can open your project and you set break points by clicking on them and then I can do listen then everything starts flashing and get a nice orange line and then what should happen if I reload this page it should pause in a in a debugger right that's what you would expect **[03:07]** but that indeed happened it stopped on this line this was not intending to work. So, ignore the last 15 seconds. Let me reload this again. And as you can see, nothing happens. This is the problem when you go to your demos and you fix everything and I forget to unfix things. Anyway, so yeah, nothing happened, right? Why Why would that be? Anybody want guess forwarding **[03:38]** >> port forwarding? No, that's not it. Let's find out why this isn't the case because that's what I'm actually here to teach you, right? So now, normally you shouldn't edit any of your standard RUL files or any other framework calls obviously, but it is sometimes useful to just add an extra line. I can bet that some of you have put PHP info in this location, right? >> I know I certainly have. And now there's some liars in the front here. So when I now load this, I get instead of PHP um PHP info, I get XDB **[04:11]** info. I made that a bit bigger because looks like it clashes with some of the Drupal's CSS here. And it will tell you exactly what version you use. So I use a very brand new version, uh basically git because while developing this presentation, I found a bug that I had to fix. So I haven't had the time to release it. And it tells you a bunch of things here in the diagnostics logs about stuff that didn't go according to plan. Um I will ignore these first two for a moment because I'll get to that in a **[04:41]** moment. It says here we tried operation in progress. Apparently that's an error if you're Linux. I don't know what. But the interesting one is here. It says could not connect to the host discovered through HTTP headers connecting to the configured address post hosted docker on internal which is what uh the def config you to do and it didn't work so it couldn't connect that makes sense because I hadn't put the ID in list right so if I click on this in here now **[05:12]** do this again and now something else shows up right the first two are still there I'm still ignoring But then the third one basically says the breakpoint file name where I put my breakpoint uh didn't work. If you click on this thing here on the side, you go to the documentation that explains why it couldn't have worked and what you do could do to fix it. But this is a common thing in so many projects. If you run something in a docker container or dab which is also docker container or a remote machine, then the path that you have on the remote machine **[05:42]** or in docker doesn't match your local pod. This is why we have pod mappings. And if you read through the documentation property of DD and other fine tools, then they will tell you what you need to do. And the traditional ways of that is to do that in your what is where does it go? Lounge.php. I thought I had that open. Too many files here. Where did it go? Where did that go? Sorry. There's too many files. **[06:14]** There we go. The normal way why you do that is you do that here. So it's just like p mapping p mappings right that's where you can edit that um but I'm not going to do that now instead my editing skills are not great instead what I've done is the launch.json JSON file is in the VS code directory VS code directory where it just stores it there and you can save it in your repository but I've created the XDA directory and I **[06:45]** put a file in there called path mapping map. So if this is in the root of your project like where you put the VS code thing then you can set up your path mappings directly in here. Now obviously I need to remove the hash that I just in added to make this line work. And basically what this line says it says match this directory on the file on where PHP runs to the file where my project is. Um at the moment you have to create this file yourself but I can imagine that DD at some point does this for you. So you don't have to think **[07:16]** about it anymore. Now with this line now made um I can now reload the page and then with some luck it stops on line 14. Fingers crossed every wording and and it certainly stopped and indeed it stopped on this line 14 which is a really nice way of having to make these pop mappings without you having to do this um um in the configuration of your ID. Now this is maybe not so useful here but the path **[07:47]** mappings can also be made between any directory and any other directory between any file and any other file. Uh this can get useful when you have templating languages like if you write your trick templates for example they get compiled to PHP files which are being run but in order to debug that you need to set a break points in the compiled PHP files that have been created but you can't do that in your ID because you need to well you can but you need to figure out where these files are but these spot mappings will allow you **[08:17]** to set a breakpoint in your template file where you're editing it and it will pause when the file gets run but it gets mapped to the correct line in your template value so you can step through your template file and see what happens there I haven't set up uh the conversion of variable names yet but that is something I'm really looking forward to as well but there are other things that you can do with here as well so let me just step through this a little bit further so first we u require the outer loader and then we want to see well what **[08:50]** happens if I do new Drupal kernel I know you will know what happens. But I have no work. I'm just stepping in. But of course, when I step into it, I don't end up in a kernel. I end up in your class loader. Now, how often do you need to debug through the class loader? Like never, right? Or going further than this, how often do you need to debug anything in vendor/composer? Almost never, right? or if you're just **[09:20]** working on a Drupal project, do you really need to go into vendor symphfony or anything like that? There's no reason to to deal with these, right? And it just makes for you to have to create extra steps. So that is something else that you can do with these path mappings. I find where it is too many things in here. I've created another one which is called skip vendor map. Well, these names don't matter what they are. Uh, but I do need to enter in map. So if I comand that out and I do equals **[09:54]** skip, you can guess what it does. It will just skip anything in vendor composer. Now for that to work, you do need to reload your current request. It doesn't do that automatically because these files are only read when PHP request starts. So I will press continue and then try again. Again it stops on the outer loader which I will jump over and then I jump into new **[10:24]** kernel. Anybody guess what's happen now? It stops in the Drupal kernel which is what you expected to do. So I think this is actually also a useful feature to have especially for skipping all this. I should shouldn't say that's loud composing nonsense because Neils might be so this is kind of a useful thing to have. Now there's a few more other things. I should go through my slides first before I speak because otherwise I get lost track. Done that. Done that. Right. So break points are **[10:55]** this is the internal protocol. But I was wanted to show you is that break points can be set on multiple different things. You have seen me clicking on the line that makes it stop on the line. But you can also set break points on when the function starts and when the function exits. Now not all IDEs have support for this. U PHP Storm and VS Code both have support for at least the call but I'm not actually sure whether it has support for return. But similarly there's also way of setting break points on exceptions **[11:26]** or break points on lines with conditionals. So let's show these as well. Right. So I will abort this so we get a nice wide screen. Um so let's first have a look at um where did my part mapping file go? So I'm going to actually disable the pod mapping at the moment. Not the part mapping the scenar because that allows me to show something else. So let me reload this again. Oh, and I need to listen. **[11:59]** So it stops on the outer loader. I want to jump um jump over it. But now I'm jumping into the class loader just because so I want to show you something here. Now if I put a break point on this line here, right? That means every time a class gets loaded, it stops here. So let me just do that a few times now. How many files are there in any sort of Drupal projects? There will be tens of thousands. >> Well, maybe maybe thousands. But if you **[12:30]** want to debug just the inclusion of a specific file, you don't really want to loop through all of them and then hope it is one of the first three because you know how this goes. It's always one of the last three in this drive. So what would in in case if I actually can check for a specific condition and then only break when this condition matches. So we have this break point here. Um, here in the bottom left, you can click the uh addit condition button. **[13:02]** So, I think this UI is a bit weird because it just suddenly appears in the middle of something that already had text. But what you can do is like there's a few things in here. You can do expressions, hit count, and a log message. Lock message I actually have no idea what it does. I think it's something that VS code does. But the expression is kind of handy because what I can now put in here is class equals where are we? Symfony. **[13:33]** My typing skills are terrible when people are watching. I think it said server back. Let's presume it says that's that's the one I tested with. Let me check. Yeah, I didn't got the name spaces wrong there, but I think it was this one. So this expression is now being evaluated when this break point hits. So when XDbug sees this line being executed, it will then run this statement. And if this statement **[14:05]** evaluates to true, it breaks. This statement is being evvelt in your PHP code. So you can do anything in there that you want to do and also all the things you really shouldn't do like running XAC RM minus RF slash right you can do that but I wouldn't recommend it but it is just PHP code that you're running in here if you want to do something more complicated you often have to put it between parentheses but your ID will tell you when when you need to do that but with this equality **[14:35]** statement now I said it I will stop this and distance again then reloads. It still stops from the outer loader like we expected and then we click next and then it stops indeed when the class is just the server back which is like the 10th or something in my list. It's quite neat isn't it? Now there's a bunch of other things in here while I'm here I should probably show remove this. So, how often have people set a break point **[15:08]** that that explanation only works when it's not in a debug request because XD does immediately what I was about to show you. How often have you set a breakpoint on the line on an empty line by mistake? Yeah, it happens as well. But what is often more common is that people set break points on lines where they think there is code but isn't actually code because sometimes PHP internally doesn't record the correct line number with the line of code that you're writing. Now if you see something **[15:39]** like that it is sometimes a bug in PHP and we have fixed many of these but also some cases when you're editing code you break one because your ID doesn't sync properly ends up being on the empty line. Now, if it's on the empty line, you think you have a break point there, but when you run it, it doesn't break. So, let me show that, too. I can only show that, of course, when I'm listening. So, if I load this now and then when I look at it, stops in the out loader. We expected that. Click next. **[16:13]** And you can indeed see that it didn't stop on the line where it's at a break point, but it stops in the next one because it's clever enough to now look a little bit further to see to hopefully guess where you thought you actually wanted to put the break point. Now, the algorithm for this is kind of interesting. So, I'd like to show you that. Yeah, we'll look at the exception break points in a moment on that. Sorry, >> maybe not. I'm out of order here. Um I'll get to that in a moment. I've done **[16:44]** that. So the other one is um notify. So sometimes people like to use Vardo debugging, right? Uh but that of course breaks up your u your page layout often. But what if I tell you there's another way of doing that? So since XD debug 31 I'm going to guess there is this Xdebug notify function which you can give any PHP variable to and this notification doesn't go through **[17:16]** the output like you get with VM or DD or whatever you call these things but instead the information gets sent over the debugging protocol so it will show up in your IDE but not in your output. So at the moment I have set no break points except for the one that drew Pernel. No I disabled that too. So if I now load this. Yeah maybe not. Let me pause this. There we go. Pause. And listen. I wish that was just saying stop program. **[17:50]** go back to my ID and well if I if I had removed the Xbook info okay I'll get that then it would have messed up the layout it did now anyway because I had forgotten to remove this line in the file right let me do that so let's try this one more time save this reload run it then you don't get any strange output but if you look in the output of the ID **[18:21]** it in the debug console it actually did dump the contents of this variable so you can then expand it and inspect what it set in there it is set to some levels deep not all of them because it doesn't know how much you want like to see after the request has ended but this is a configuration that that you can make so yeah you can now dump things that don't mess up your layout and you still can't in your ID see what happened in here which I think is also a nice thing to see. Right, back to the slides. **[18:52]** Demo that. All right, so the break points that I showed you with a demo. Let's have a look at how this works. Now, in order to figure out how this works, you need to create log files and I will I didn't quite know how to do that. So, u I don't know how to make extra configuration settings in in DV because I don't know what I'm doing pretty much. But there's actually a way of adding things in the project that I have. So this is very small, isn't it? It's so small I can't see it. **[19:23]** Um, where does this go? It's in DD web builder. I put in this extra Docker file. Now, this does a whole bunch of things. I copied this from the documentation and modified it because I already showed you that I wanted to run something XD running in git and this used to work with just pack or something that was already in the distribution. But the important thing is more is that I actually load my specific in file. **[19:56]** I wish I could have figured out a way how to get it from the local file system. There must be a way. So maybe somebody can explain it to me. Uh but if I open this, it should open in my browser. Oh, it so it downloads it. Um but we can inspect what's in there by going into my data project. Uh I use PHP. I can't I can't remember where this file is, but it is down this **[20:27]** file here. So there's a few changes that I've made in here. So, I basically copied the standard one but added these three lines because the path mapping that I showed you is still experimental. You need to turn it on. Um, and then I've set the log level to 11 because I like 11. 10 is fine, but anything hard higher than 10 will work. And there's also this tmp/xdebug lock. So, I will delete that **[20:58]** file because there's a lot of things in there now. uh then reload my Drupal phone and then did I listen? Yeah, that should have worked. So if I now open this file, there's a lot of stuff in here. There is so much things in here that basically tells you everything that's gone on with the communication between XBook and PHP. It tells you which part **[21:32]** mapping files have been loaded. It tells me that there was an error with one of them because there's no path mappings in it. That's because I put a hash in front of it, right? Uh it will tell you about control sockets. I'll get back to that in a moment. It will also tell you which headers it looked at to figure out where that actually needs to make a connection. All of these things in here. And once it finally decided to make a connection, it says it's connected. And then you get the protocol information. Now this is very verbose XML **[22:02]** um not useful for most people unless you find a buck and XD debug and then I will ask you to make one of these things. But the interesting thing is it will also tell you exactly which files and line numbers it solves and which ones it tries to map. This is a lot of information right in one request you easily get megabytes of information. So don't leave this on all the time. But once it starts running, you see it looping through all these lines and it tells you that some of the things are being mapped to not stop. **[22:33]** And at some point there's a lot of stuff in vendor, isn't there? Oh, this only works obviously if I actually have set a break point. I'll put it here. Do it again. We'll get there. Reload this. Did it stop? It stopped. Continue running. And now I have a useful old file. **[23:03]** So again, it does the same thing. But then at some point when you do run, it says it figures out that it's actually breakpoints being set. So that's an optimization in XD that makes sure that it only checks for line break points when a function has had any line break points set on it. That saves a lot of time actually. one of these things that I do look at. But yes, I then sees that we have this break point here that we set on index PHP23 and it matches against our current location which is 14. That doesn't match. **[23:36]** Um, okay. So I was trying to find where it was actually setting it. So the ID sets breakpoint sets on line 22. It figures out that that is actually uh on this file on the on the remote file system. It figures out that the line number is in the big block of code the largest range. It finds that line breakpoint line or line 22 doesn't have executable code on it and then it will methods to concentrate. So all of these **[24:06]** things are in this log. Um, this sometimes goes wrong for reason, but this log fault contains everything in there. And even for one request, how big is it? 24 megabytes. It's not so bad. Not so bad. So, this log file is useful. How does this work? I showed you that. Check the log. So, return values. That's the next thing I want to showcase here. I don't need this anymore. **[24:37]** Um, so let me set a break point here on I remove this. Set a break point on this one here. This one here. No, refuses to do that. There we go. Uh, reload the page again. Oh, and listen. Reload the page. Listen. So I'm in this **[25:07]** send method. I don't know what it does. Also, I don't know what it returns. It's possible that it doesn't return anything, obviously, but So, let me step into this. Now, it sends some headers, sends content, flushes through. If flush is true, which it is, uh, so if it isn't true, then it returns this. So, it's not going to do that, right? Skip over that. Okay. and then it does a return of this. Now obviously if you have returned this **[25:38]** you can inspect what this is at the moment but there's many situation where return will do return and then the name of a function or a method and in order to for you to figure out what the return value is the only way what you can do is first assign it to a variable and then return a v variable right that's no longer true because I can do step in here why did that work here Okay, I'll try another one. **[26:14]** This worked in when I tried it. Oh, okay. It worked here. Let's say we have array key exists. We do a return of that and then of course you need to figure out what the return value is. But if in a situation where PHP and XA can detect there is something to return and it can show you which apparently isn't always the case or there's a bug somewhere then it will tell you in the local here that there's a return value and it will tell you what this value is. So this is an extra state **[26:46]** in between returning and it being returned. I picked a line of the return itself but that's not really true. it is sort of in the middle in between but I need to show a line somewhere. So that is very useful in my my opinion. So it should work the same for uh any non-building function too but I don't know okay here for example I return this array the parameters array **[27:17]** from this because otherwise you have to assign that first then you can also see all these things I think there is a distinction if it's return this compared to anything else I don't know why but I have to figure that out later so you can inspect the return value which I think is a nice thing to Let me run this to the end of the request. Now the other thing is there's VS Code has this thing like break on everything. That's very ominous, isn't it? But what it actually means is a break on all the **[27:48]** exceptions, all the notices and warnings. So let me click that. Now I don't know whether Drupal uses exceptions under the hood even if everything goes right or maybe there's notices. We'll find out when we reload this. If not, I know how to make it do this. So, let me reload this. It stopped somewhere. At least stop for my break point. Great. That's what we wanted. And then run. So, apparently Drupal is notice free. That's pretty **[28:19]** good. So, let me break this because let me just throw the kernel. This is not something you can do. This is going to cause issues obviously but um it can demonstrate the value the feature name here. So notice it then stops on >> so I have not done what >> it says. >> Oh yeah that is helpful. Thanks for being more awake than I am **[28:51]** here. Okay. So when I have saved the file and tried again then it actually works because in the variable pane here it will now also give information about the error in here. So in this case it's an error that is being thrown by PHP itself which means it doesn't have a line number and file access attached with it. But if it had it will also show up here. And this extra display thing here is something that VS Code picks out out of **[29:21]** this extra fake local exception message. Um that um oh there is a line of file number. Apparently it doesn't show you that in this thing here but I guess it's in the call stack. It plucks this information out of this pseudo exception variable to then being able to display it. It also shows like nice nice big and rats which is is kind of nice to have, right? So that is also something that's new in here. Yeah, I get more errors and **[29:51]** then PHP finally gives the ghost and dice. Oh, and now we get nice orange errors as well. You can guess why these are orange exceptions, right? So these are the new things in a standard debugging protocol, but there's a few situations where I run sometimes long running scripts, long running scripts that do lots of different things. I'm going slightly away from Drupal because I I couldn't find any standard way where Drupal uses **[30:25]** this kind of thing. Um, but this is something I call control sockets. Now for this I have this other script running here in the background. This is a very useless script. I will show you what it does once I figured out how to switch my projects. I haven't figured out how to have multiple projects open at the same time. Okay. **[30:58]** Oh, I broke something. Let's just try that again. There we go. It did work in the end, but I don't know why I did that. Right. So, I have this very useless script here. Where where is it? Work manager. What it does is it's 22 lines big. It has this worker class which has a method **[31:28]** obtain task. And what it does, it sleeps and then returns a random number. And then I have this long running loop that basically does obtain task. Basically sleeps and returns a random number. And then I showed the random number. Now this script is already running, right? It's already running in the background here. Now how do I debug this? You can't really, right? because XDBook only sorry P XDbook only initiates a **[31:59]** connection to the ID when the script starts but that's already running now let me put VS code in listen mode quickly and again in indeed it doesn't do anything even though it's on listen mode and then so there is a new command on the command line now which I haven't really spoken much about and certainly not documented yet which is something called XDbug PS. **[32:29]** XDBug is like a command line tool written in Go doesn't matter where it's written in but and it is in version 0.01 but I never had to change it so that's good enough isn't it? But what you can do with that is basically request all the PHP process that are currently running. So here it says that the command this is the worker manager that I'm running on the command line. Uh it will tell me which execic version it runs what the memory usage of it is and also **[33:00]** how long it has been running that is in seconds. So yes nearly an hour by now. So it has created lots of useless random numbers. It's like creating bit Bitcoin. Um but the interesting thing is now um I can also run pause and then it should pause. However, because there is a multiple PHP script running at the moment, I need to tell it which process ID I want to debug. So I do that at the **[33:31]** end. Yep, sorry. It goes first and then it says ID connection signaled. That sounds ominous. What has it done? Uh, nothing. Why not? Let's try it again. Oh, now it works. And the reason why it now works is because the first time you do it, it it tells XD make a connection to the to the IDE, which it has done. **[34:03]** But there's no break point set. So it still doesn't break, which is obvious because it wasn't instructed to do so. But when you do it for a second time, it will then also immediately initiate a break point on that line. So now it then stops on the next line where it could stop. Uh there's some timing issues. So it might not exactly be the first line, but it will stop as soon as it can. And now it has stopped here on this line 10. And it can inspect which random number is going to be returned and inspect other variables and indeed step over it. **[34:35]** Uh, is this I was wondering why did it wait but does it sleep on my program? That's fine. And when you're done with this, you figured out your butt or not. Uh, you can press continue. And then of course, if you now set a break point, it wouldn't stop again because XDbook can only or the ID can only send break points when XD can a break state. But it isn't now because it's just running our script, right? It still runs in the background here creating more useless random numbers but I can still run pause **[35:05]** again and then because the connection with the ID is already there it will then stop on my breakpoint line. So this is how you can nowate any sort of longer running script to still debug like these tasks that are pulled of cues which I think is a nice way of doing that. Now I don't know one thing what happened here is that I don't know what this other PHP process is and where it comes from. So I need to go figure out what it is. **[35:37]** Um because the way how this works is XDB's sorry the tool signals XDbug to um to to within 250 milliseconds of this see whether it can do this break point but if it doesn't reply then it decides I can't connect. Now usually every 250 millisecond is fine because unless you run like a long running query in your database you will have a function call at least every 250 milliseconds hopefully these things these control sockets are kind of useful to have but they only **[36:09]** really work on the local system. So if I would want to do this something running in a docker container the xdebug ps also needs to run in your docker container. The intention is that this gets built into uh ids like VS Code. So that if any of you has ever done debugging with C++ code, you might know that that you can attach a debugger to an already running process and this would allow the implementation of something similar for PHP as well. Um, it doesn't have to be a **[36:41]** long running process, but of course PHP requests are usually so quick that you wouldn't have the time to select it from the list and then attach it to the request because this is per request. So this functionality is there. Um, it's sort of experimental on Windows uh, but it has been contributed um, and it seems to work. I mean the tests passed, so that's good enough for me. And now the next step here is to get us integrated into IDE as well. People using VS Code **[37:12]** sometimes use like this uh remote kind of thing. There it would work because that would run in the same container as where your code runs. In other cases, we need to come up with clever ways of also being able to stop process in containers, but I don't know quite know how to do that yet. Sure, we can come up with a solution there, too. So, these are the control sockets. Now at the moment it only has PS and pause. If you have ideas IDs for other things that you could do out of band while PHP process is running for example maybe give a **[37:43]** stack trace at a corner location which is certainly possible to do then let me know and we'll see what we can implement there. Okay let's talk about future features that's by the way hard to pronounce. So the next thing after the native pm mapping when I've got that done I would like to work on a time travel mode. Now most of the time especially if you run a if you have your software running on one of your clients they encounter a bug in **[38:13]** the application how do you debug that right it's really hard thing to do or near impossible so what this feature would allow you to do is it you would tell xdebug to please record the whole request including all intermediate steps variable assignments function calls dump that into a file and then you can ship that file to you as developer first and then debug it as if it was a currently running script. You can step forwards, inspect all the variables, step backwards. Um, but the script won't be running **[38:44]** because you PHP doesn't allow stepping backwards. So, this is a feature that I think can be really useful. It's also going to be a lot of work to implement. So, I don't think that will happen in a year's time. And then sometimes um I run into people that have problems having things connected from PHP to the ID. That happens when there's a shared development server and people work from home. Um there's no way of making network connections between **[39:16]** these locations. Sometimes you can get around it sometimes by doing SSH tunnels, but it would only work for one developer at a time. There's proxies that also work, but there's also other constraints with it, right? should have clicked play on tape there. Um, so yes, XD bit you need to remember needs to make a connection to the ID. My logo is PH PHP Storm could do something else. When there's containers involved, there's sometimes issues with picking the right name. DEV solved that by using host of Docker internal and other solutions available too. Uh, sometimes **[39:48]** you have an actual firewall in a way. Firewall. That's my firewall. There's my file. uh it's not a good idea if your fireball is actually on fire. Um but that makes these connections impossible, right? So there is I've developed a way around XDbook called XDbook cloud. Everything needs to have a cloud product now, which is basically a way of rooting around these networking issues so that you can still debug these kind of situations. It's just coming soon. It's been running for two and a half years, but I don't know how to make animated graphics, so **[40:20]** this is going to stay. Um so yeah that has been running for a while and there's plenty of people that makes use of that. All right Xbook cloud if you want to look at Xbook is open source many people talk about that open source needs to be sustainable. I don't want to talk too much about this because I don't like talking about these things but it is important that open source becomes sustainable. you can become a patron if you'd like to. But when I do things like that, um there's also support for businesses. Uh if you want to support me, that also comes with support back for me. Obviously, it goes **[40:51]** both ways. Uh but when doing these things, I also think it is important that you talk about not only signing up for support, but also what you do with your time. So, every month I try to make like a big list uh of all the things that I've worked on. Uh this one is from August, but I've created newer ones for that where it lists basically line by line the things that I spent time on. Um I also have like a monthly a monthly newsletter to these people **[41:22]** explaining a little bit in more detail what kind of things I have been working on or what kinds of bugs that I encountered or what the next version of PHP has been messing up and I need to then fix again. All right, that's sort of what I had to talk about. I think we have four minutes for questions or queries as my slide says. Anything in the room? There's one in the back. >> Yeah, >> I was trying to make it exercise there. >> One thing I would really like is um sometimes it happens that a function is **[41:53]** called two times and somewhere in the ST trace is the point where it kind of >> ums so that one function is called one time but then at that point it does two calls to some like in a loop or something. Yeah. And that's exactly the it could be like from the function I'm interested in like 10 levels up and that's what I want to find. So I want to find in the ST trace to see which of them have been repeated since the last uh point it happened and which of them have just been been called once. So if I have a record and then I see it one time and **[42:24]** then I see it the second time and I want to see which of the other function tech have been repeated since then. >> Oh, it's super interesting. >> Yeah, I don't have an answer for that right now. Okay. >> Um, >> yeah. How would you >> I don't know how to do that. Let's have a chat afterwards. >> There's many questions that Oh, you got the mic. Okay. >> Um, XD Info looks interesting. What version of XD do I need to use? Uh, or **[42:56]** do I need to be on the cutting edge? >> Well, microphone is here. uh XDbook info got introduced into 30, but I've been improving on that since every version. I would always suggest that you run the last possible XDbook version that works for your version of PHP. So I don't know which PHP version you're in at the moment, eight hopefully. And if as long as you're eight, then XDbook 34 and even 35 which hasn't been released yet will also work. So I would always recommend to run the latest version of software. **[43:27]** And that is not just an XBook thing, that is an software thing. >> Yeah. >> Yes. Oh, hi. >> Uh, quick question. Yeah. >> Um, coming from another platform, we where we do debugging and we have an execution pointer >> where we can >> turn back time a bit, go up a few lines and re-execute the same code. Is that something that will be possible in the future? >> So, yes, the so the time travel mode will allow for that. There's also at the **[43:57]** moment somebody has written a command blind guey tool um for XDbug. I think it's called XDbook 2. I might have to look that up where they have actually implemented that in the uh ID itself or in the debugger itself. But it would only do that for the last function that's being executed. That already helps a lot. But it would be easier if Xook itself did that because it can be much more memory efficient with this kind of things. So **[44:27]** yes, that would also be a thing you can do slightly step back in a function to figure out how a specific variable was set or why it was set which is usually the case where you want to look at that. Yes. Yes. I would like to implement that but it's going to take some time. >> Hey um a question about West Code and XD integration. So if we have um an object for example render area or something and want to find uh some value there do you **[44:58]** find any way to do this for example if you want to find the string hello in the long nested object or array uh how how to simplify this um I'm not sure whether VS Code or any ID lets you search in the stack traces or in all the variables that are in there. Um, it is not something that I can probably easily do in XDbook itself, but it would be worthwhile trying to figure out whether this is something **[45:28]** that IDE can implement. Um, I would suggest if you're VS Code user to send a feature request to the author of that project. He is usually quite responsive to these things. Um, and let me know and I'll chat with him about that. >> Yeah. Okay. because now it's easier to make the HTML output using dump and use browser but it's >> not the good way to do this. No, but yeah, it would be a nice way if you can **[45:59]** search in the stack trace for specific strings of values. I agree. >> I think store has >> Okay, today I learned >> I think >> time's up. Sorry guys and girls. Um, the slides are going to be online if I haven't put them online yet. Uh, I think I have. If you have any further questions, there's my email. Feel free to email me. I will give you an answer. It might take **[46:29]** time. Otherwise, you can find me on Masttodon on derek rpb.c.social. I will be around for most of the day. So, feel free to come up and have a chat. And uh one thing I should also say that I have some stickers, but there's only about a dozen of it. So, I'm not quite sure how I'm going to distribute these. In any case, thank you very much. I hope is useful and enjoy the rest of the time.