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

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. 

Posted on

My Raspberry Pi Weekend

Extended weekend really. I spent my four days off this week without too much to do, but I felt super productive because it’s my first days to myself since the holiday. Amongst catchup up with washing and actually doing some drawing I set up my Raspberry Pis again.

I’ve currently got two Raspberry Pis set up – A Raspberry Pi 2 which is the main one I use. I’m doing some home automation stuff and the Raspberry Pi 2 acts as the hub of that, with a Raspberry Pi Zero feeding it data from across the room.

I just want to talk about some of the stuff I’ve done, because I’m not ready to post tutorials and code snippets yet, but I will soon!

Firstly, I have set Dexcam back up. So tweets of whatever my rabbit is up to get posted once an hour. It might be a little boring compared to last time as he now has a two floor bunny mansion, so if he’s not on the top floor it won’t really show much. The aim is to change it to sense motion, wait a second then take a picture? But for now it’s fine the way it is.

I’ve also been working with the Phillips Hue API so I can control the lights using my own code. I wasn’t going to touch them at first as anything I’d need them to do can be done via the Hue app or IFTTT. But that attitude wasn’t letting me play with code so I’ve added a few scripts to the Pi which I can call for fun.

Speaking of calling the scripts, check this out:

This is my (currently very ugly) control panel I have been making. Any scripts I’ve written can be called on this page. The bunny button takes a one-off Dexcam picture and tweets it. The lights below let me change colours or do a colour loop on the light behind our TV. 

I’m yet to add our other lights to the system. We did however discover our Hue lights fit our fish tank. SO GUESS WHAT THE RAINBOW FISH BUTTON DOES?

I know I know, that’s the most pointless thing you ever saw. But it looks freakin’ cool. Did I mention we got new fish? Uh, yeah, nothing to do with me that…

Speaking of nothing to do with me being the reason we got new fish; I also bought a temperature monitor for the Raspberry Pi. It’s attached to the zero because we needed it hidden away behind the tank and no-where near the Dexcam Pi.

So on my control centre screenshot the final figure is the tank temperature. It’s actually a little high in that screenshot which Terry is fixing. The final plan now is to set up a text alert in case the tank temperature suddenly drops, you know, in the totally hypothetical situation where someone might accidentally unplug the tank and kill them all. That, coupled with a smart plug where we can remotely flip it back on? 

I totally don’t sound like I’m trying to make up for a past mistake, huh?

I guess the best part of this whole thing is me just coding some junk for the control centre. I’ve levelled up in PHP because of it though, and written my first functional object orientated PHP scripts.

That, coupled with some Python, Bash and some pretty shady hacky things have been really fun. For example, I’m not the best coder, so the only way I saw to get the temperature to display on the Raspberry Pi 2 hosted control panel was to have the python script taking the temperature dump the output into a .txt file, then SCP the file to the main Raspberry Pi, then the PHP reads and displays it. 

Which seems rather convoluted but for me it was a good way of discovering some of the things I can do. 

Anyway, I’ve rambled enough without really showing any code or circuit set-ups so I’m going to work on prettying them up so I can write some guides!