Entries tagged as php
Google Charts API Simple and Extended Encoders in PHP
Friday, August 14. 2009
Google's charting API has been around for quite a while now, but I've only just needed to actually look at it. It became immediately obvious that I needed a PHP encoding function, so off to google I went. Though I found several implementations, they were all incomplete or deficient in one way or another (and it didn't help that there was an error in google's extended encoding docs), so I've written my own based on several different ones. Both simple and extended encoders support automatic scaling, inflated maximum and lower-bound truncation, so you can pretty much stuff whatever data you like in, with no particular regard for pre-scaling and you'll get a usable result out. They have an identical interface, so you can use either encoding interchangeably according to the output resolution you need (contrary to popular belief, the encoding to use has very little to do with the range of values you need to graph). By default, the full range of possible values is used as it just seems silly not to. I deliberately omit the 's:' and 'e:' prefixes so that you can call these functions for multiple data series, and I include a function that does just that. You still need to generate your own URLs and other formatting, but that's a different problem. Read on for the code...
Continue reading "Google Charts API Simple and Extended Encoders in PHP"
The web developer's holy vhost trinity
Friday, March 20. 2009
When you're developing web stuff, working with projects in path names (i.e. not at the top level of a domain) can be difficult (gets in the way of absolute links, rewrite rules etc), so you often need to set up a local apache virtual host, stick an entry in DNS and create an SSL certificate before you can get on with the serious business of doing some real work. This can get to be a drag when you do it a lot, but there is an extremely elegant solution that means you'll never have to do it again...
Continue reading "The web developer's holy vhost trinity"
Web Hooks, Callbacks and Distributed Observers
Wednesday, March 4. 2009
Someone at AMEE pointed out to me that there's been a flurry of activity around so-called "Web Hooks" when I referred to the concept. This is quite heartening as I thought of this a couple of years ago and implemented this in Smartmessages early last year! I call them callbacks, but the idea is the same - it's essentially a distributed observer pattern. I couldn't figure out why nobody seemed to understand what I was on about... When I get some interesting event (e.g. a message open, mailshot completion, clickthrough etc), I ping a user-supplied URL with the appropriate event data, pretty much the one-liner that Jeff alludes to. The reason we do it is that sync with external systems (usually CRM) is something that were always running into, and there seems to be no sensible, generic way of dealing with it other than this, so I'm surprised it has not been discussed in this context before.
There's one downside as far as I can see - it is highly dependent on the receiver to be able to handle the event in a timely fashion. This isn't an issue if you're connecting say, Yahoo! to Google, but it could be a big problem if you connect Google to your Wordpress blog... My experience of CRM systems is that they are simply too slow to cope with the high rates of traffic that we are likely to generate, for example, if we point a stream of ~200 events per second at a CRM system, it will probably just bog down and fail (I'm thinking of the SalesForce API here which typically takes 1-2 sec to deal with a single SOAP API call). Retrying will only make this worse. I have two solutions for this: limit events to those that don't happen so often (kind of lame!), or alternatively, use an outbound message queue to rate-limit the sending (Amazon SQS and Memcacheq spring to mind). Queueing works, but you lose some of the real-time aspect. Ideally clients would implement their own incoming queue in order to allow them to process events at their leisure, but this is mostly beyond the vast majority of web authors (or at least those that host the CRM systems that we hear from!).
Anyway, it's nice to know that I'm not completely barking...
PHP London Conference 2009
Monday, March 2. 2009
From this truly excellent conference, I took away some good memories, some new ideas and a nasty bout of conference flu. There's nothing quite like being in close proximity to a few hundred people to really spread things around...
Highlight for me was Aral Balkan's keynote. It's always nice to see someone showing plain enthusiasm, and I couldn't agree more with him about the "lost magic" of computing. Had a chat with him afterwards about AMEE and other things. He also seems to have put together some odd but dull things that I had noticed a need for - EU VAT codings and ISO language references as web services!
I didn't really enjoy David Soria Parra's talk on sharding. It all came across as very negative and many of the ways of doing it and coping with the fallout were not really discussed. No mention of MySQL 5.1's partitioning (which is limited, but is at least a start), or more radical approaches like Sequoia.
David Axmark's talk on Drizzle was more interesting than I expected, nice to see effort being put into this direction.
Microsoft really does seem to be trying a bit harder these days - their CSS test suite for IE8 is very welcome, and the effort they are putting into PHP, apache and other projects benefits many people. It has to be said that while it's not a mainstream product, Surface is really pretty cool to play with.
Chris Shiflett's talk was excellent too; his demos and examples were particularly good, and entertaining.
The post-conference social was great fun, I met lots of nice new people. After our move to France I suspect it will be harder to get to events like this, so I should make the most of them while I can!
I've had several ideas for talks that I'd like to do (I get sick of email sometimes!), so I guess I need to get a bit more proactive on actually submitting them to a call for papers.
PHP Barcelona Conference
Wednesday, September 10. 2008
PHP Barcelona's conference site just went live. I'm speaking on email in PHP at the conference, along with PHPLondon regulars Zoë Slattery and Scott McVicar. It all happens on Saturday September 27th. Tell your friends!
PHPLondon08 follow-up
Monday, March 3. 2008
I think it was Juliette that was asking me about spam filtering in PHP. I didn't think that was such a great idea (spamassassin is slow enough!), however, it seems that some others do.
The framework shootout session was very interesting. It was nice to see Toby jumping into CodeIgniter with such ease - it contrasted markedly with my own difficult initiation into CakePHP! There was mention of Kohana which I'd only seen a couple of weeks previously, but looks pretty good - I had always been put off CI by its support for PHP4, so a PHP5-clean version is very appealing. This article spells out the differences.
The shootout was, um, augmented by a heckler who had decided that all frameworks were "criminal" because they didn't conform to the letter of the "rules of MVC" (though MVC is really a pretty loose term AFAIAC). He wouldn't name his mystery preferred framework, but I later found out it was Agavi when I saw it demo'd by its creator. It is indeed very nice, and has distant ancestry in Mojavi (as used by Symfony). One of the things that I was impressed by is that it uses (of all things) HTML for marking up templates. This is an elegant reversal of what I've seen before, where form elements are typically generated by helpers (requiring syntax that you don't know). Why mark up a form input like this (vaguely CakePHP style):
<?php echo $htmlhelper->textinput('name', 'name', 20, 50); ?>
when you could do:
<input type="text" id="name" name="name" size="20" maxsize="50" />
and still get automatic server and client-side validation and ajaxy feedback goodness, but also have it play nicely with HTML editors like Dreamweaver? It also makes for a great deal of sense when generating non-HTML output. I can't think why other frameworks have not done this before.
Agavi also has very elegant routing so that a single controller function is available across all access methods, whether HTML, JSON, SOAP, XML-RPC or whatever. Makes CakePHP look very dumb.
Anyway, so maybe this heckler had a point of sorts.
I have to say a big thank you for the compliments I've received about my talk. Maybe it wasn't so bad after all! I'll get on with doing the remaining audio ASAP...


