Posted on

Kay’s ‘Getting started with XDebug for WordPress’ Guide

Over the weekend I spoke at WordCamp London about using XDebug, it was a quick lightning talk, and I wanted to write out what I went through and some additional bits because a few people said they’d like something like that to get them started. Plus usually after a WordCamp I usually just post a simple blog about ‘Oh yeah this happened and it was fun’ so I wanted to write something more useful after it!

It’s also worth mentioning that I’m not a developer, so this is a very basic ‘How to get started’ guide showing you just some of the things XDebug can do. It’s a much more powerful tool than outlined here, and you should definitely do some extra research after reading!

So uh, yeah! Here goes.

Setting XDebug up on a local environment (MAMP)

The easiest way to get started with XDebug is with MAMP on your computer, because it comes already installed. If you’re using a different local development solution there’s tonnes of guides online for a variety of them. I just used MAMP because I found it by far the quickest and easiest to set up for beginners.

Here are the steps:

  1. Download and install MAMP from: https://www.mamp.info/en/

When MAMP is installed and opened you will have a window like the one to the right. Click ‘Start servers’ to fire up your local environment.

This will load up a webpage with useful resources for your local development area. It’ll look like the screenshot below – and will include links to your homepage and php info page.

 From here, click on the ‘phpInfo’ page, this gives you useful information about the version of PHP and the modules associated with it running on your test server. we specifically want to use this page to find out where our php.ini config file is located.

Now we know where the file is located, we can navigate there on our computer. So if you go to the folder where the php.ini files located and open it up in your preferred text editor program, you can edit some of the options here. We are going to enable XDebug by finding this line at the bottom:

;zend_extension=”/Applications/MAMP/bin/php/php7.2.1/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so”

This is the XDebug module, which is disabled by default, to enable it all you need to do is remove the semi-colon from the start and add whichever XDebug options you want to enable, so here’s what my XDebug lines look like in php.ini after enabling it:

Finally, I enable onsite errors on my test server so I can see them immediately on the page. To do this I change the line in my php.ini file currently saying ‘display_errors = Off’ to:

Then use the MAMP main screen to restart my server. When that is done you can check your php.ini file to see if XDebug is listed as enabled, or you can go ahead and start breaking some PHP code, because with display errors enabled it will show you on your homepage like this:

You don’t have to enable onsite errors, but I find them easy to work with, instead you can choose log files to send them to, for a full list of options check out: https://xdebug.org/docs/

Profiling

Profiling is a super handy tool that XDebug offers. It helps to find out where memory issues lie, by saving data about your called functions in a cachegrind file.

To enable profiling, you first need to add this to your php.ini file (or possibly .htaccess depending how your server is set up and if you’re using actual online hosting):

php_value[xdebug.profiler_enable]=1

This enables profiling, and your site will start generating a cachegrind file full of useful insights. For ease of obtaining this, you can set your own path for where the cachegrind file(s) will be saved:

php_value[xdebug.profiler_output_dir]=/var/www/vhosts/mysite.co.uk/httpdocs/

From there, I can download and save my cachegrind file to my computer. Opening it will give you all the information obtained, but it’s pretty much unreadable because of the file format. But with a program like Webgrind you can open the cachgrind file in a much more readable and user-friendly format. For Mac users like myself however, the easiest way to do this is by installing and running Qcachegrind. Which is installed as follows:

  • Open Terminal on your Mac.
  • type ‘brew install qcachegrind’
  • Type ‘brew install graphviz’

Now you can run Qcachegrind and open the file you saved earlier, as follows:

qcachegrind ~/Downloads/cachegrind.out.21991

Obviously change the directory to wherever you downloaded and saved your cachegrind file. When this is ran it will load up a window that looks something like this:

This screenshot does contain a lot of information, but it is far more readable than just opening up the cachegrind file in your text editor. The left side panel gives you load times for individual functions, in order of what takes the longest. With this you can easily identify if a plugin is slowing your WordPress site down, because it might have a specific function taking a long time here.

The right side gives a more graphical representation of these load times. Bigger boxes are bigger and longer-to-run functions. It does give a lot more information than this, but this is mostly what I’ve used qcachegrind for, and its definitely worth running if you want to get some deep insights in to what is running and causing slowdown on your site.

Breakpoints and FYIs

I don’t do a lot of hardcore development myself, so breakpoints aren’t something I regularly use. But they’re definitely worth looking in to because it allows you to use XDebug with your code editor and set a line in your file to stop the script running at that point.

I’m going to link to the documentation for Atom for that, but yeah, check breakpoints out:

https://atom.io/packages/php-debug

Other things to be aware of when running XDebug on your servers are:

  • XDebug is resource intensive, so if you do enable it on any live hosting, make sure you turn it off any time it is not being actively used by yourself to debug code. Ideally just run it on your staging.test environments.
  • Keep in mind on-site errors will also need switching off if you don’t want them showing up.
  • Cachegrind files and extended error logs can fill up server space quickly, so again, only enable it when needed!

Thanks for reading through this, if anyone needs further help getting started with XDebug feel free to get in touch. I’m not sure how good I am at writing tutorials so if anyone gets stuck I’d love to know if something needs making clearer!

Also check out 34SP.com‘s WordPress hosting as we have XDebug ready to run on our servers which helps us to help you debug your site!

Check out the official documentation for a full list of options and features and have a rad time debugging! – https://xdebug.org/docs/

Posted on

The rad time I had at WordCamp Dublin 2017

34SP.com were sponsoring Dublin’s first WordCamp which took place over the last weekend. The WordPress team specifically couldn’t all attend due to other commitments, so the attending team ended up being myself, Siobhan and Pete.

Pete and Siobhan ready for takeoff!
Pete and Siobhan ready for takeoff!

Man, did we have a great time at this one. It was my first time going far enough out with colleagues to warrant flying. It felt particularly important to make it a good one, because without Tim and Keith it made myself the only one from the WordPress team there. So without sounding lame as heck I wanted to make them proud.

We kicked off the adventure by meeting up to get the flight from Manchester to Dublin, Siobhan is a very nervous flyer, so take-off was a bit shady, Pete was ace and stepped in to be comforting and lose a hand to her squeezing. Haha, but after a very quick flight we arrived in Dublin!

We stayed at the Holiday Inn Express near the airport, it was actually just above Santry park so it had a beautiful view as you left the building. The hotel was also one of the few close enough to the venue in relation to what else we were seeing when making out admittedly late booking. So I feel we did well with it.

After freshening up we spent the first day exploring a little of the centre of Dublin, because Pete and Siobhan hadn’t been before. We had an ace time; Hard Rock cafe was doing a vegetarian week which meant they had some great food choices for Siobhan. Can we talk about those amazing buffalo cauliflower wings? I’m still emotional.

We then went for a few drinks in local bars which were recommended by the Hard Rock staff. Dublin is an expensive city, so the staff recommended a bar with a lot of two-for-one offers; Capitol Lounge on Aungier St. It was a good shout, we enjoyed it there and tried another place around the same area which sold some nice ale. Sadly I forget the name of the second place.

Knowing we had to be up the next day we retreated back quite early, and at the time we got in the taxi we then became aware of sponsor’s party for the event. Bad timing meant we missed that, and ended up being so rock ‘n’ roll we played charades until we were tired. Charades was hilarious though, because we were all terrible at it and shouted at each other a lot of our terrible acting.

At the event

We (well I) was up at 6am because I couldn’t pass up the free breakfast at the hotel. Siobhan joined me soon after and we were all ready to leave around 7am. The event was held at the DCU Business school, and we arrived and had the stand set up by 8am ready for people arriving.

Flaunting the last three swag bags.
Flaunting the last three swag bags.

We met some really nice people at WordCamp Dublin. It was fun because we met more new people than usual, being over the water and all. The atmosphere was really relaxed, so much so that I probably felt the most comfortable I ever have leading up to my talk.

I did what was probably my last presentation of ‘Making kitten GIF galleries fabulous‘ for a while, as I feel ready to move on to new talks now. I got some really good feedback on the presentation, as usual. It also meant a lot when we got people afterwards telling me how they found it useful and practical. Queue big smiles!

We were so well looked after by the organisers and the catering. Biscuits, fruit and sweets were readily available. Volunteers checked in to make sure we had everything we needed, helped us with some trouble putting the iPad stand up and helped us get t-shirts even though we were late getting our tickets! They spoilt us really, which we appreciated.

Talks! I went to a couple of talks, one I was particularly eager to listen in on was Tammie’s talk on ‘Getting to know Gutenberg’, as I was a little behind with knowing what all the fuss was about. I’m actually now writing my posts in Gutenberg, because I’m excited about the plugin and it’s development. So I plan to write some reviews and thoughts on that.

Tammie's talk on 'Getting to know Gutenberg'
Tammie’s talk on ‘Getting to know Gutenberg’

I also attended a talk by Gerald Glynn on how to ‘Build a bespoke page builder’, which was him showing a very unique way of using custom post types to create something really special for his clients. I enjoy seeing what people do with the custom post types plugin as it really fires up your imagination for just what you can create in WordPress.

A large chunk of my Sunday was spent at the happiness bar/help desk. As we were advised there were a few people roaming around and looking for help. I spoke to some lovely people there too! I remember offering some image optimisation tips off the back of my talk, helped a lovely lady called Carrie get set up with Yoast and then myself and Robbie enlisted some CSS advice from Julia on the organising team. So I learned some handy helpful tips too. One of the best things about WordCamps is the opportunity to get some really top notch advice from people who use WordPress every day.

Other bits and thoughts

Other highlights of this weekend included the best sushi I have ever eaten: At a local chain restaurant called Musashi. Sadly the chain is exclusive to Dublin at the moment, but the food was beautiful!

Amazing Japanese grub!
Amazing Japanese grub!

This was Pete’s first WordCamp, and he owned it, he was so helpful the entire time, and enjoyed chatting to people about WordPress and our rad support team. He and Siobhan also attended some talks I did not, but I hear really good things about the Lightning Talks specifically.

I totally needed this WordCamp. I’ve been in a minor rut lately because I’ve been working hard to pass some exams and I’m struggling to get there. No big deal really, but WordCamp Dublin has rejuvenated my enthusiasm and interest in learning.

I remember the first time I attended a WordCamp with 34SP.com, it was WordCamp Manchester a few years back, and I remember being inspired as heck because I was genuinely thrilled to be working in web hosting, and with WordPress daily.

Man I sound so lame, but I used to spend so much time when I was younger playing with websites and learning about how the web worked, it’s easy to lose sight of how thrilling that is when you hit a bump. So uh, yeah! A big thanks for WordCamp Dublin and it’s organisers for making me feel energised and excited to learn more and work hard. 🙂 


 

Posted on

Adventures at WordCamp Bristol 2017

Man this weekend has been rad. Siobhan, Tim and I travelled down to Bristol for their first WordCamp – and it was great! We were representing 34SP.com as usual and I did some speaking. Here’s what we got up to!

So on the Friday we travelled down, I scored 16 on Popmaster, yeah I know I’m ace. When we got there there we got a little confused as there are two Premier Inns right next to each other, but we eventually found the right hotel. 

The first evening was the Speaks and sponsors dinner, which was held in a cafe just a little out of the town centre. It was nice. They served a really good veggie chilli and we chatted to a bunch of people in the community. We left, idk, around 9pm? We were going to call it an early night but we got the munchies and ended up having a curry from a random street cart type thing. It sounds really dodgy, but it was nice. 

The first day of WordCamp saw us needing to be there for 8am. The conference was held in The Watershed – an event space/awesome cafe/awesome bar. The venue was perfect, there were two tracks, so two rooms for talks. The rooms were right next to each other with a small corridor where sponsors set up. Our stand was between the two doors, so we got lotsa people chatting to us!

I watched Elliott from Raison.co‘s talk on mistakes he made during his startups, which emphasised a healthy attitude towards starting a business and why you need to invest enough time before people will become interested. Because apparently ‘nobody cares’. Heh. 

The Watershed sold amazing breakfasts, by the way. We ended up getting breakfast there because we skipped it in the morning, and even of the last day we walked down there again. The event catering was really good as well. Like, can you tell I really liked this building? On the Saturday the streets filled up with market stalls just outside which sold loads of books, craft items and homemade cakes and breaks. Siobhan got some nice vegan fudge and I had banana and honey cake. C:

I did my talk that afternoon – Making kitten GIF galleries fabulous. I feel like it went really well actually, I hope others did. Well, the general feedback was that people found it useful, as it was focussed on image optimisation and I tried to put as much content in as I could. I also used my own drawings for some slides, which is a bit of a confidence step for me because I tend to be shy about throwing my drawings in people’s faces. At the same time I was worried about including too many because I wanted the talk to be more informative. Anyway, it went down well from what I can tell. Still working on those nerves a bit. 😐 But I feel pumped to talk again now!

The evening meal was really nice – make your own burritos! And we sat around with people talking about what talks we enjoyed whilst having some drinks. Apparently the party went on until quite late and they found a nice ale pub – which I went to the day after. Siobhan and I may or may not have been itching to catch some Eurovision and missed the end of the drinks. 😐

On the Sunday I went to Edmund’s talk on WP-CLI, which gave advice on how you can use it to automate setups and working with themes – WP-CLI is awesome, so I was plugging his talk during mine the day before, because I used WP-CLI in a few of my examples.

Mark Jennings also did a talk on Google Analytics, and offered some handy tips on how to get useful information out of all the stats it offers. I use Google Analytics myself but mostly just look at referral data, so it was handy to get advice on how to actually use the data productively.

As well as this we did a lot of talking to people, everyone was super friendly. Tim and I did some on-the-go support at the Happiness Bar, I got to see some familiar faces who I haven’t seen in a little while. It was a really great weekend.

All in all it was a hectic, but amazing weekend, and even though it was their first WordCamp, Wordcamp Bristol turned out to be one of my favourite ever WordCamps. The organisers and volunteers did an amazing job and I had a blast!