PHP Kent – The first meetup

Thursday 18th April 2013 at the LOL Bar in Maidstone.

It’s been a long time coming (the idea started in 2010), but my business partner and I have finally got around to organising a local PHP user group in Kent (UK).

I attend PHP London frequently, but am hoping to meet local developers and share ideas outside of that. Not able to get enough of PHP user groups, I plan to attend both on a monthly basis! šŸ™‚

For more information on the meetup, like when the next event is scheduled, and to RSVP – please head over to the meetup page.

Getting the raw POST or PUT data of a request in ZF2 MVC

If you’re sending raw data to ZF2 over http (perhaps a json document), you can use the “getContent()” method of Zend\Http\PhpEnvironment\Request.

How does this work in practice?

In a controller you might want to do something like this:

1
2
3
4
5
6
7
8
9
<?php
namespace Application\Controller;</code>
 
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
 
class IndexController extends AbstractActionController {
    public function indexAction() {
        $data = $this->getRequest()->getContent();

But if you’re always expecting a certain format, say JSON, a controller plugin could give you back the array or object rather than a lot of json_decode calls in your controllers.

The plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
 
namespace My\Mvc\Controller\Plugin;
 
use Zend\Mvc\Controller\Plugin\Params as ZendParams;
 
class Params extends ZendParams {
 
    public function fromJson() {
        $body = $this->getController()->getRequest()->getContent();
        if (!empty($body)) {
            $json = json_decode($body, true);
            if (!empty($json)) {
                return $json;
            }
        }
 
        return false;
    }
 
}

And then its as simple as:

1
2
public function indexAction() {
    $data = $this->params()->fromJson();

Help! Sometimes getContent() doesn’t return my data.

The method uses file_get_contents(‘php://input’) to get the raw data from the HTTP request. Unfortuantely, the php://input stream can only be read once per process. I did have a plug-in that called file_get_contents(‘php://input’) too, and if $request->getContent() gets called after this, it will be empty!

RB Fitocracy wordpress plugin released

I’ve just released a new WordPress plug-in to display Fitocracy stats on your blog. Give it a whirl and let me know what you think:Ā http://wordpress.org/extend/plugins/rb-fitocracy/

The next version will have more information available (total points, most recent workout, etc). As soon as its possible (via some sort of official Fitocracy API) I’ll be removing the need to enter your own account details too!

Virgin Media broadband in MEx – will this post make it online?

For the last few weeks my Virgin Media broadband service has beenĀ unusableĀ during peak times. Unfortunately Virgin media don’t consider this a service fault, merely an inconvenience. When do VM expect me to use my broadband, when I’m not at home or in bed?

The sad thing is, this is a massive problem for VM across the country. A quick look through posts on their forum, a large percentage of them are about poor service at peak times.

I’ve been monitoring the situation for the last week, this is what I’ve found so far. 50% pack loss on most evenings and for the majority of Saturday (today).

Virgin Media MEx Service status
Virgin Media MEx Service status

If it continues, I’ll have to find an ADSL provider with a decent contention ratio.. does anyone know of one? šŸ™‚

Wishing for a Fitocracy API

So its been a while since my last post. Rather than come up with some decent content I thought I’d waste time updating the theme of the blog and coming up with a new whizzy plugin. Progress, right?

I was hoping to get my Fitocracy stats up on the blog as a widget, but turns out its (next to) impossible at the moment. I get that an API isn’t always first on the agenda or something that users should expect to have – but it would be nice!

As soon as I can get a feed of my profile data I’ll be adding the widget and then releasing the plugin to the world. I’ve put in a request on the Fito forums, lets see if anyone has any ideas.

There are some other unofficial Fitocracy APIs out there, but none seem to work at the moment!