PHP
Calling all PHP Rockstars!
Apr 21st
Hey everyone
We’re looking for some skilled PHP developers to help us innovate with and improve on AMFPHP. If you think you’ve got the goods to help us get this project insanely powerful (but still simple and easy to use), drop us a line!
-
Ariel Sommeria-klein – Project Lead (ariel@amfphp.me)
-
Danny Kopping – Development Lead (danny@amfphp.me)
Introducing Aerial CMS
Apr 11th
Well, I finally let my irritation get to me… I’ve been developing Flash, Flex & AIR applications for two years now – most of them pulling data through AMFPHP from a PHP-based back-end. In those two years, I’ve tried nearly all the suggested solutions for managing content on the back-end and pulling it through to the front-end; Drupal, MODx, WordPress, Symfony. They are all fantastic PHP-based frameworks and systems, but they don’t allow me to develop applications the way I want to. So, as a consequence of this combination of irritation, frustration, egotism and flat-out boredom with writing the same code, over and over, for each project, I’ve decided to build a CMS – Aerial CMS.

What is Aerial CMS?
Aerial CMS (named Aerial because it was the first word i could think of with “RIA” in it) is a simple content management framework. I decided to rethink the concept of a content management system, because – the way I see it – CMSs these days are about content management AND content presentation. I think that these two massive areas of development & design need to stay very far away from each other. They are like brother and sister to us now, but sometimes – when stuck in a room together for so long – they breed and the results are disastrous (on top of being scandalous!).
Design Philosophy
Look at how the MVC (Model View Controller) pattern came about: software engineers found that separating application logic from presentation from data has serious design benefits. Now, i’m not attempting to bad-mouth all the incredible efforts of the CMS developers… I’m saying that for Rich Internet Application development, it really becomes a chore to use systems like Drupal or Symfony because they were not meant to be used in that way. They do what they do superbly well, but for RIAs they fail to impress me.
Aerial CMS has been built from the first line of code for optimized Rich Internet Application development. It focuses only on content management and development tooling, and wants nothing to do with how you present the data. It’s certainly a change from the standard model, and i’m convinced about how I want to develop my RIAs, but that’s why i’ve put out this early release – to see if you all agree with me. This CMS still has a very, very long way to go; it works well for most situations but the tools haven’t been developed yet.
Technology
Aerial has been built on two very well established and loved open-source frameworks, namely AMFPHP 1.9 and Doctrine 1.2.1. The Aerial framework is built for compatibility with PHP 5 only. Aerial enforces no rules upon you when you get down to developing your back-end code, but it does stick to Doctrine’s method of generating database tables and models. In essence, once you’ve set up your database schema, you can do whatever you like
you can plug into Doctrine’s API or you can write your own code; it really gives you the freedom to code the way you’re comfortable with.
Tutorials and Videos
I’ve made a Getting Started video to get you familiar with the framework and i’ll be writing a series of tutorials in the Wiki section of the Google Code page for Aerial CMS. I’ve also got plans for a couple more video tutorials, so keep checking the site for updates or follow me on Twitter (@dannykopping).
Comments, Suggestions, et al
I’d love to hear what you have to say (as long as it’s in English – being monolingual sucks)! I’m very open to suggestions, any offers to help contribute would be welcomed and all constructive criticism is encouraged!
AMFPHP is back!
Feb 2nd
Today is a wonderful day!
I have teamed up with Ariel Sommeria-klein to revive the legendary AMFPHP project that spawned a whole new dimension of Rich Internet Applications. Together we have brought AMFPHP 1.9 out of beta and made it compatible with PHP 5.3. We have also completely rewritten the AMFPHP service browser and we have several improvements planned for AMFPHP 2.0.
If you would like to help contribute to this great open-source application, please contact us.
AMFPHP Genie v0.2
Dec 13th
AMFPHP Genie (0.2) is a simple tool to help you get shit done using Flex and AMFPHP.
Check out http://dannykopping.co.za/amfphp-genie/ for more information!
PHP Thumbnail Generator
Oct 6th
Here’s a very simple PHP class that i wrote to make thumbnail generation on JPG, PNG & GIF images really simple and painless.
NOTE: You will need to have GD installed on your server for this class to work!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | < ?php /** * Image thumbnail generator * Based on the work from http://sniptools.com/vault/generating-jpggifpng-thumbnails-in-php-using-imagegif-imagejpeg-imagepng */ class ThumbnailGenerator { public $sourceFile; public $destinationFile; public $width; public $height; public $format; public $scale; /** * ThumbnailGenerator::__construct() * * @param mixed $sourceFile Path to source file * @param mixed $destinationFile Path to destination file * @param mixed $width Thumbnail file width * @param mixed $height Thumbnail file height * @param string $format jpeg, png or gif * @param bool $scale Scale thumbnail * @return */ public function __construct($sourceFile, $destinationFile, $width, $height, $format="jpeg", $scale=true) { $this->sourceFile = $sourceFile; $this->destinationFile = $destinationFile; $this->width = $width; $this->height = $height; $this->format = $format; $this->scale = $scale; } /** * ThumbnailGenerator::generate() * * @return */ public function generate() { $fromFormat = "imagecreatefrom".$this->format; $sourceImage = $fromFormat($this->sourceFile); $sourceWidth = imagesx($sourceImage); $sourceHeight = imagesy($sourceImage); if($this->scale) { $ratio = $this->width / $sourceWidth; $this->width = $sourceWidth * $ratio; $this->height = $sourceHeight * $ratio; } $targetImage = imagecreate($this->width,$this->height); imagecopyresized($targetImage,$sourceImage,0,0,0,0,$this->width, $this->height,imagesx($sourceImage),imagesy($sourceImage)); $imageFunction = "image".$this->format; return $imageFunction($targetImage, $this->destinationFile, 100); } } ?> |
All credit goes to http://sniptools.com/vault/generating-jpggifpng-thumbnails-in-php-using-imagegif-imagejpeg-imagepng for the snippet!
Sample usage:
$tg = new ThumbnailGenerator("image.png", "thumbs/newimage.png", 100, 100, "png"); echo $tg->generate() ? "Thumbnail generated successfully" : "Failure!";
PHP Process Viewer for Unix
Oct 4th
While working on a project lately, i needed a script that would allow me to find certain processes with PHP and inspect their running times, etc. After struggling for a little bit, i came up with the following script that can output a plain view, JSON or XML of the running processes whose names match a regular expression passed to the script. The script can also kill all processes that match the search term.
This script is by no means complete, but i thought i’d share it with my readers ![]()
Save it as process_viewer and run it from the command line.
Please keep in mind that this script is still in a very rough form and should not be used on enterprise products; it’s merely a bit of buggering around for fun
Click here to download the script.
Usage:
process_viewer [search_regex] [mode] -o [format]
- search_regex – search term to find running processes (defaults to .+)
- mode – script mode (defaults to view)
- view | kill
- -o – flag to indicate that the script must output in a specified format
- format – output format (defaults to plain)
- plain | json | xml
Sample usage:
./process_viewer bash view -o xml
A Belated Announcement
Sep 9th
Well, it’s been a week now since i officially left my old employer – IceBlue InfoTech (which has now been acquired by Virtuosa)… I decided to start my own freelance consulting, development & training firm, creatively named Danny Kopping Consulting. Unfortunately, all the cool names were taken, so i went for the one that i knew wouldn’t be taken
.
I’ll be focusing primarily on building advanced, highly customized Flex-based systems and websites, using PHP, MySQL & Apache on the back-end. I’ll also be doing some training on the side for Flash & Flex (with a little PHP). Hopefully this freelance venture will pan out well and i’ll have even less time to muck about than i did before
A special thanks goes out to my best mate Neil de la Harpe for doing all my corporate branding!
I’ve set up a temporary site over at http://www.dannykopping.co.za/. Check it out…
XAMPP 1.7.2 Released
Aug 20th
It’s finally here! The new version of the XAMPP stack has been released…
This new version includes PHP 5.3.0, Apache 2.2.12, MySQL 5.1.37 & phpMyAdmin 3.2.0.1 (amongst a myriad of other features). You can check out the new stack here. I wouldn’t recommend upgrading if you are using AMFPHP or CodeIgniter as the new version of PHP (5.3.0) will mess up quite a few things – i learnt the hard way.
I upgraded from 1.7.1 to the new version on my Linux Mint virtual server that i run within my Vista installation (damn you Adobe! Just release your software on Linux already!) and i came across an error in one of my AMFPHP installations on a project that i’m working on at the moment:
(mx.rpc::Fault)#0
errorID = 0
faultCode = “Client.Error.DeliveryInDoubt”
faultDetail = “Channel disconnected before an acknolwedgement was received”
faultString = “Channel disconnected”
message = “faultCode:Client.Error.DeliveryInDoubt faultString:’Channel disconnected’ faultDetail:’Channel disconnected before an acknolwedgement was received’”
name = “Error”
rootCause = (null)
I think that AMFPHP is still the simplest and easiest way to use Flex remoting with PHP (i recently wrote an article for FFDMag on this topic – look out for it in the September edition). However, it doesn’t have the greatest error handling mechanism ever…
Using Charles Proxy, i managed to find the real root of the error, and it appears that there is some sort of discrepancy with the dates/timezones in Gateway.php in the core of AMFPHP.
To resolve this issue, open the Gateway.php file in the core/amf/app folder in your AMFPHP installation and go to line 213. You need to tell PHP which timezone you’re in, and you can paste the following code:
date_default_timezone_set("Africa/Johannesburg");
above this line:
$dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days"));
I reside in Johannesburg, South Africa so that timezone will apply to me, but if you live anywhere else, you’ll have to find the pertinent timezone to use.
That should fix things up…
Parsing XML in PHP5 with SimpleXML
May 16th
PHP5 includes a library for parsing XML data called SimpleXML. This class (and associated classes) is a fantastic way to parse XML data in PHP5. Parsing of XML comes into almost every project i work on, whether it be creating/manipulating RSS feeds, sending data between Flex and PHP, and whatever else the client wants really
Below is the XML data i will be working with in this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <languages> <language year="1999"> <name>ActionScript 3.0</name> <description>ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player platform (in the form of SWF files embedded into Web pages).</description> </language> <language year="1995"> <name>PHP</name> <description>PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in standalone graphical applications.</description> </language> <language year="1995"> <name>Java</name> <description>Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.</description> </language> <language year="2007"> <name>LOLCODE</name> <description>LOLCODE is an esoteric programming language inspired by the language expressed in examples of the lolcat Internet meme. The language was created in 2007 by Adam Lindsay, researcher at the Computing Department of Lancaster University.</description> </language> </languages> |
Now, say we wanted to parse this XML file using PHP, and extract the name of each of these languages…
1 2 3 4 5 6 | <?php $languages = simplexml_load_file("languages.xml"); foreach($languages as $language) echo $language->name."<br/>"; ?> |
In the above code, one can extrapolate that SimpleXML will go through your XML file and assign the nodes to an array, and in that array it will create an untyped Object with the data assigned to properties of that Object.
Simple enough, right?
Now, what if you wanted to access an attribute of each of these languages (in this scenario – the year attribute of each language)?
That’s also really easy with SimpleXML! You can reference the attributes of each node by using array notation…
1 2 3 4 5 6 | <?php $languages = simplexml_load_file("languages.xml"); foreach($languages as $language) echo $language["year"]."<br/>"; ?> |
Ok. So what if you wanted your returned data to be mapped to a class? I.e. each element in the array that is returned must be strongly typed to a class, rather than the unspecific stdClass Object that’s returned by default… This can also be done with SimpleXML!
Here’s the Language.php class i created for the returned array elements to be typed as (note that it ,must extend the SimpleXMLElement class):
1 2 3 4 5 6 7 8 | <?php class Language extends SimpleXMLElement { public $year; public $name; public $description; } ?> |
…and the code to return each array element as a Language Object:
1 2 3 4 5 6 7 8 9 | <?php require_once("Language.php"); $languages = simplexml_load_file("languages.xml", "Language"); foreach($languages as $language) { print_r($language); } ?> |
If you look at the output, you will see that the year attribute is not assigned to $year property of the Language class, but rather to a @attributes property. However, if you add this function to the Language.php class, the attributes will be assimilated to their respective properties:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php class Language extends SimpleXMLElement { public $year; public $name; public $description; public function attrToProp() { foreach($this->attributes() as $prop => $val) $this->$prop = (string) $val; } } ?> |
…and run the script again, but adding this line of code:
1 2 3 4 5 6 7 8 9 10 | <?php require_once("Language.php"); $languages = simplexml_load_file("languages.xml", "Language"); foreach($languages as $language) { $language->attrToProp(); // -- add this line print_r($language); } ?> |
