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 darkest sock story you ever heard

Okay, so… I am like, crying with laughter right now. 

I’m working on a new project, which I’m not ready to show to the world yet. But it involves socks. I needed some blog articles about socks, so, because I was feeling lazy I went over to iWriter.com to pay some strangers a few quid to scribble up some 300 word posts.

What I requested, was an article about two watermelon themed socks. One pair of socks was striped with watermelon print, and the other is a copy and paste watermelon print. I wanted an article that compares the two socks so people could decide which they liked best.

And wow, this article? I can’t tell if it’s spam, genuine or some weird combo of both. But read this! Er, warning, it gets a little upsetting in the middle. 

Obviously this is the most epic sock story you have ever heard. And you’re damn right I paid this writer and tipped them. Maybe a little dark for my tastes, I might edit the ending to have the socks become friends again?

I also learned a lesson in not being lazy and writing my own content. LOL.

I love the internet.

Posted on

My little ideas for a Final Fantasy VII sequel

I’ve been replaying my favourite game of all time; Final Fantasy VII. I replay it every few years because I just get to a point where I miss being told the story. That might sound weird? But Final Fantasy VII is my all-time favourite story ever.

I’m excited as heck for the remake of it, but I also really hope that one day Square do a Final Fantasy VII sequel. Not in the same vein as the Final Fantasy X or XIII sequels, but more of a completely full and brand new Final Fantasy game, just set in the same world as VII.

Being the loser fan that I am, I have some ideas of how I think it should go, and I just want to talk about my ideas for a potential Final Fantasy VII sequel.

The setting

In my head the best time for a Final Fantasy VII sequel to take place is around 15-ish years after the original game? Cloud and the gang would be fairly older, but it’s enough time for the events of VII to have changed the world enough that we get to see what life is like after meteor.

We could see how the world handles electricity now, would there be electricity? If so – how do they get it now? I’d assume mako is out of the question, but we’ll get to this in the story bit later.

Playable characters

I’d steer clear of using the same cast as the original Final Fantasy VII. They’ve been through enough, okay? Instead, I would like to see new characters take the spotlight, but that doesn’t mean they can’t be characters we already know?

How about Marlene as the main character? Barnet’s daughter takes up the role of narrator in the Advent Children movie, she’s clever, and she’s someone the fans know and like. 

Marlene’s companions would include adoptive brother Denzel from the Advent Children move, and because we want characters from more places than just Midgar we could also bring Priscilla in the mix. Priscilla would be bound to have some badass Dolphin-blow like move.

If any Final Fantasy VII characters were going to be playable characters, it makes sense for Red XIII to be – his age-span means he wouldn’t really be much older at all 15 years later, and he has unfinished story from the first game. Where did he find others of his kind to make those cute little wolf kids we see in the ‘500 years later’ part? Maybe a Final Fantasy VII sequel could answer that!

The story

If there was a Final Fantasy VII sequel, I really wouldn’t want another Sephiroth/Jenova based story. I’d want new heroes and new villains.

Having Marlene and Denzel around for story-telling purposes would be great, because they are both orphans and don’t really know anything about their parents. Marlene could find out about Dyne when they visit the Corel area. Who knows where Denzel comes from?

In terms of a ‘main villain’ and real threat, I’m not too sure, but thinking about what we know from the end of Final Fantasy VII and Advent children – Sephiroth had a big following, someone crazy, but new could easily show up.

Are those monsters in Mt Nibel’s reactor still there? What if they got out, or someone set them lose? And their mako poisoning created some kind of zombie effect. I’m just spitballing ideas now, but there’s potential in the world Final Fantasy VII left behind. 

Other little ideas

It’s my assumption that the Final Fantasy VII world is pretty much in darkness for a while after the first game because mako was used to power anything electric. The original game was filled with messages about being green and the environment, so I think the sequel would still focus on some similar morals. 

I think older characters, like Cid and Barret might be working together on renewable energy, I mean, that map has a LOT of water. 

Gold saucer would still exist, and either be totally screwed because of the electricity situation, or if that wasn’t a factor it would be thriving, depending on which; the area would either have exactly the same mini games or brand new fancy ones. 

The WEAPON monsters should make an appearance, but in Final Fantasy VII they only appear when the planet is under threat, so how would they show up? Maybe this bad guy I can’t think of wants to find them, wake them up and destroy the planet that way? That’d be pretty bad-ass.

The Highwind would still be in use, because why would the characters travel in anything else? 


I think I’m out of my ideas now, I was just playing along and coming up with ideas for a new game whilst I played. I’ll probably rush back to add more as I progress!

TL;DR – Final Fantasy VII needs an awesome sequel. I don’t know if many fans would like my ideas, in fact, someone actually has a lot of the opposite ideas to me. But give their post a read too for some other ideas!

And finally, a link to my favourite blog article about my favourite game, just because fellow fans should really read it.