 Okay, right, I'm from Switzerland, by the way, in case you're wondering. Not from Germany, that would be an insult. Sorry, right, Exdebug, who here is using Exdebug, or Centibug, or PHP debug? Okay, awesome, some people, not a lot. Who is actually a PHP developer here? Okay, you should all be using Exdebug, but I'll get to that later. So it does a couple of different things. It provides new functions that you can use for debugging, etc. It changes the behavior of some core functions. It can do profiling, but most importantly, what I'm going to focus today, mainly, is that it implements a remote debugging protocol, which is super useful. First, though, do not run it on live servers. It has an impact on performance, usually, and if you run it the way I run it, it's also a bad idea security-wise. So it's purely for development purposes. It's purely for finding bugs, etc. Do not run it on live. Also, if you get used to using Exdebug to solve issues, you might get really annoyed watching people who do not use Exdebug, trying to solve an issue by, you know, it works like wild amp, printf, throwexceptions, change files around, etc. That is the reason why I'm talking about this, because I want to see more people use it. I always get annoyed when people try to solve big problems in a very complicated stack using frameworks or stuff like Magento, and they're trying to understand what's going on over several layers of abstraction using printf debugging, or printr debugging in PHP. Right, so just quickly, all this stuff it does besides debugging the new function, new functions, it adds to PHP when you install it. You get co-coverage analysis, which is handy for people who like tests. It has a couple of functions that give you more information about whether you could output where you are right now, which file are you, what line, etc. Also one that's particularly useful I find is Exdebug get headers, if you're working a lot with sending HTTP headers back from all over the place in your code. This gives you a list of all the headers that have been set to be sent back with the HTTP response. This is now complete. I'm a bit minimalistic with this. I didn't really have a lot of time to prepare, so I didn't go to everything it does. It may do other things you might find useful. I do not use these things. It also changes how PHP behaves in some ways. One thing it does, it includes the stack trace in error messages whenever PHP shows an error. I think I have some screenshots of that later. WarDump can do colors on the console if you want it to. A limitation it introduces is it introduces a function nesting limit of 100 functions deep, so if you have really weird software, there's a chance it might not work anymore, it might crash. It will output that and tell you what's going on. Again, other things might change, this is not complete. So this is a normal error message, as you may know, if you have display errors on in PHP configuration. This is all the same error message it looks like when you have exabug installed, which gives you a bit more information, can be useful. So for profiling, it generates files that you can analyze with the usual tools that you can use for other cache grind files, cache grind, there are some good utilities. So basically you tell exabug to profile a particular session, you get a file, you analyze that. Yeah, you see where the performance issues are, but that's the topic for another talk. This is like performance optimization. I'm more focused on finding bugs. So if you want to do remote debugging, usually when I have like a new system running or something, if I just want to get it running really quickly, because that I think is the main reason why a lot of people do not do remote debugging because it seems a bit complicated to set up, but it's actually quite easy if you do it this way. You need to install the exabug extension to PHP. You can either install through your distribution usually in Ubuntu or DBM-based installations. It's a package. You can use a pickle if you want to do that. And for my way of using it, you basically need these two lines in configuration. You will get a new configuration file for exabug somewhere in slashetc, slashphp5, slashfpm, if you use php5fpm, slashconf.d, slashtwenty-extabug.com or something. You put in these two lines apart from the usual line about loading the PHP extension. And I'll show you later what that is, the connect back and the remote enable. And then you have to set up your IDE if you use one. Exabug also ships to the common line client, if that's your thing. I find it super useful. I use it together with PHPStorm. Who uses PHPStorm? Some Eclipse users, maybe? Okay, so Eclipse also supports the protocol that PHP-ex-debug uses for the debugging sessions. So when you set up your IDE, you need to first configure your IDE to accept incoming connections for the debugger. And you need to set up path mapping because the protocol uses, when it talks about files, it uses the absolute path on the server. So the absolute local file path on the server. So you have a local copy of the source code. And you need to tell it how to match an absolute path that it gets from the server to your local source code. I'll show that to you later. And then you can start remote debugging. You set breakpoints, or one breakpoint at least. You enable your listener in your IDE to wait for incoming sessions. And then you start your debugging session in the browser. Back to the configuration, I have ConnectBack mode enabled. So again, there's different ways to set up Xdebug. To me, the most convenient one is the ConnectBack, which basically means you tell the server, the web server basically, it's running your application. I want to start an Xdebug session. ConnectBack to me, and it connects back to your IDE. You can do it other ways. You can set it up in a way that your IDE kind of connects to the server, et cetera. This is the easiest one, very quick to set up. Again, potentially security, a security problem if you have shared servers or something, if the server is public. If you configure it like that, everybody can start the debug session. And if you start the debugging session, you can get a lot of information. You might not want people to have. Yeah. Live demo. Let's do this as soon as I get out of this. You're awesome. Right. So for the setup of the IDE, oh, that's a bit small. I'm using PHP storm here, as I mentioned. Just going to show you very quickly in the settings. You can't read it, but I'm using the filter here and put in Xdebug. I got some configuration here that says, can accept external connections that is set. So I already have it configured. Some other options that may or may not be useful to you. And then I have this little icon on the top left. This little thing here, this is telling me whether I'm listening or not currently, so you can enable and disable it. You don't have to do it in the configuration all the time. If I want to listen to sessions, to incoming debugging sessions, I enable it. So now my IDE is listening. And I set a breakpoint somewhere in my code. Let's say I have an issue with my code. I don't even have records. I have an issue with my code right here. I set the breakpoint. I go into my browser. And this setup, by the way, it's a vagrant setup. Who's using vagrant? Okay, some people. So I'm running, this server is running in a local virtual machine. So it's sort of remote, but it's still local on the computer. You start a debug session by attaching a URL parameter called, again, you can't read it, but it's called xdebug session start, and then you can give the session a name. I usually use one, that's it, but I can give it any name. When you do that, and you set the, as soon as the request goes out, and you hit the breakpoint, that should probably change the resolution. Does that work with your setup, Michael? It's not, it's probably, maybe? Scale. Oh, no, the scale's weird. Is that dirty? Yeah. Let's see if that works. Yeah, okay. So now I have a running session. The process running PHP on the server is suspended, let me sit down. And my debugger realizes that I hit the breakpoint, and the debug window here pops up automatically in PHP storm. I don't know how it works with xlips. Sure, it's similar if somebody's experience tells us. And I have the whole, not only do I have the local, contacts of local scope that I can explore with all the objects that I have that go like deep, several layers deep. This is a bit more information than you can get out by randomly wall dumping stuff into your browser, I think. There might be smarter ways to do this as well, but this works. So I have to complete local scope. I have the global variables from which I might be able to extract, say, stuff like database passwords, et cetera, depending on how your application is set up. This is a typo tree CMS application, so it's relatively complex. So I have the local function and its scope, and I'm at my breakpoint, I can step over functions. Yeah, for people who are not familiar, in a debugger you can step, like just align further in the current file you are in. If it calls a function, you can step into it. So let's see if I find one, where are we currently? Yeah, this isn't gonna work. Let's go step over each. So this, for example, now I'm at a point where I'm about to call a method on another class. So I can say, okay, I wanna see what's happening there, so I step into that, and here I can either also step into the next method or step over, so go to the next line in this slide. This way I can navigate and execute step by step, and yeah, if I need to go back, if I need to get the whole, say the scope of any earlier, basically I can move here to the whole stack, to the whole call stack, all the way to where the thing is actually starting. And again, explore local variables, all the objects that are in the current scope of that particular position in the stack. And then if I'm done with my problem, or I wanna let it run again, I'm gonna stop stepping, I can let it run again, and the browser session loads. If it hasn't timeouted until then. All right. You should also check out, there's other debuggers, there's sent debuggers, which is commercial, so I'm not sure if that's actually still a thing, people still use it. But there's also PHP debuggers, which is part of PHP 5.6 now. Who has used it? Okay, nobody. Kai has, but he's, okay, I see. So I'm not sure what's gonna happen in the future with PHP debuggers, at the moment it doesn't implement a remote debugging protocol, but nothing that I think can talk to IDEs that's like widely implemented. So Xdebug has the advantage that it works with a lot of different IDEs. Yeah, a lot of different implementations, client implementations of the protocol. Okay, one thing that happened to me last week when I was using Xdebug, I was trying to debug a problem on the other side of the planet on a server in Switzerland. I set up Xdebug because I didn't want to copy the whole environment to my local computer, I was just supposed to find one bug. I set up Xdebug, I asked it to connect back to my machine, it didn't work. After a couple of hours of searching, I found that it has a hard-coded connection timeout for the connect back and that timeout is 200 milliseconds. So if you run it over a slow connection and it takes more than 200 milliseconds to establish a TCP connection, Xdebug will just die before it actually starts the session. So I actually, I tweeted the developer of Xdebug. That's all I use Twitter for anyway, to render people. And yeah, he seems to be open to make it configurable. But until then, do not use it over slow connections because it might not work for your purposes. Also, it's one of the very few projects that have a flatter button if people use flatter. That's like the first time I actually could flatter something so they got my whole like $5 or something. If you use it and you should really use it, please use it, please go home and set it up if you don't already have a setup. If you use it to find bugs, if you find it useful, probably a good idea to flatter or donate to the project. All right, are there any questions? Yeah. Does the five-part mapping work with the five-part system? So if I'm packaging my modules into five-fives. I would assume it does. Yeah, as long as the files are the same on the server and... Okay. But will it still be able to pick it up from within my IDE and be able to track? I wonder, can the... Do the current IDs actually browse to the Power Files? The Power Files is basically a zip file. I'm not really sure how... The problem is, can your IDE go like, oh, we need this particular file in this Power File and we'll display it to you now? I don't know, I don't work with it. It's structured exactly as... Yeah. It's basically a zip file. It's a zip file of different files. So you'd have to have a client that can do that. As we said, I don't know. But the library gets to a web server and most of our code is packaged into five-fives. Yeah, I would not use... I mean, as I said, you use it on development servers or like local development instances and I would not use far on that, I'd say. I don't see the point in that, ideally. And maybe the path mapping because I didn't show it the server configuration or server-specific configuration. It's very simple in XDBack, in PHPStorm. You set up a server connection. Name doesn't really matter much because it's a connect back and then here you have the mapping. Here you have the local files and here's the absolute path on the server. And that's it. I would assume something with file files. You can probably debug it but I would think not all clients might support it. Does at least everybody get what this can be useful for? More or less. It's not like I was just talking to nobody. Okay, cool, awesome. Because it is really, really, really useful. And whenever I force someone to start using it, they keep using it. It's just the initial, you need to set it up. You need to know how to use it. And then after that, it saves you literally hours of time. Especially if you often have bugs that take five hours to find. If you work with code that you haven't written yourself, some complex frameworks. How does it work with a MVC framework? Have you tried using this for a MVC framework like KakePHP? Yeah, I mean I do some symphony stuff. Typotree is basically like part of it IMVC. And I think where it gets a bit tricky when there's like too much proper software engineering in place and you have dependency injection and things like that, things like that. You might not always have the objects that you want in your scope. But I find it still quite useful. Yeah? I'm quite new at this, but recently, I was using a XD bug and you've seen to me and it was a database, it was some database connection and it keeps getting out of the tri-catch block. So after one day, I figured out one of the settings was that I didn't set it to not now. Is this like a common, is that? XD bug, you didn't set it to XD bug? No, the database. So XD bug didn't help me out, it just keeps going out of the catch block and it couldn't catch one of the arrows. And I don't know, maybe it was related, I mean, my question I guess would be in that sense that could XD bug do something bugging database. So I mean, my question might be quite simple. Well, you might want to use it. Say if you're using a framework, you have like several layers of abstraction until you hit the actual code that sends queries to the database, so you might want to use this about to hook in there and see what gets sent to the database. Maybe that helps. No, I'm fine, but... Yeah, we can take us offline. Yeah. What he says is true, you can borrow it at the point before it hits the database and inspect the variables. And inspect the variables before it actually gets thrown into the database connection. I think it sometimes turns a lot of... Oh yeah, they have it. It's just that one thing that got me... Did they click me, not now? That's enough. Okay. Right. All right, that's it. Thank you, Claudia. Awesome.