Archive for the ‘php’ Category

Insight, Facts and Hmmms

November 30th, 2008

I’m a big fan of Google Insight.  Mainly because it burns time when I’m bored and provides lots of “hmm” moments.  Its a service Google provide that lets you see search volume against a range of other factors such as geography, time, etc.  I thought I’d put a few together that may be of interest to you all.

Django is HUGE in Russia

I have no idea why this is.  Maybe because Django sounds slightly Russian?  No thats ridiculous.  But just look at those numbers – compared to the US and the UK (doesn’t appear) its huge!

Why do the Russians Love Django?

Why do the Russians Love Django?

Rails is in Decline

The Google searches tell no lies.  It seems that Rails is in decline while Django is on a steady and solid incline.  Vive le Django.

My Heart Bleeds

Everyone Forgot How to Use PHP’s substr Function

A collective dose of amnesia seems to have struck the world as the search term “substr” seems to have had an 80% increase in recent years.

Surely its Not Hard?

Surely its Not Hard?

Scala? Don’t bother.

Scala was big a few months back with a sudden influx of tutorials and discourse posted to dZone.  Unfortunately looking at the graph its pointless bothering with it.  On top of that Guido doesn’t think much of it either – and he knows his languages.

See that Bottom Feeder?  Scala.

See that Bottom Feeder? Scala.

Canadians Love Merb

I like Canadians.  They were never quite so anti-British as the Americans.  They still have our Queen as their head of State and have none of the beligerant crankiness of republicans in America and Australia.  Its no suprise then that they like Merb – a lot.  Merb is of course ‘Rails-that-works’.

God Save the Queen

God Save the Queen

Well I’m sure you’ve all enjoyed these stunning eye-openers.  If I find anymore then I’ll be sure to let you all know.  In the mean time – have a good day.

Open Source Asterisk CRM Platform

November 14th, 2008

Built in PHP this Asterisk CRM looks pretty wicked.  Its an open source Customer Relationship Management application which hooks into an Asterisk PBX.  It looks nicer than I sound though so I’ll shut up and slap you with some pretty pictures…

Asterisk PBX CRM

Asterisk PBX CRM

The Info Link

Using the Asterisk Manager PHP API

July 19th, 2008

Well it’s been a while since the PHP Asterisk Manager API was released and I’ve yet to produce a clear and definitive example of its use.  So here goes.

Prerequisites

Your Asterisk server must be set up correctly before this API can ’speak’ to the server.

  • First you’ll need to ensure the Manager interface is active and you’ve set the correct permissions (If you’d like this explaining please leave a comment).
  • Secondly make sure you are setup with the ability for two endpoints to call each other.  This won’t work if you have one phone on the server.

Install

Firstly you’ll need to get hold of the library and there’s two routes to take.  You can either install via PEAR or simply checkout the source from the Google Project:

svn checkout http://asterisk-php-api.googlecode.com/svn/trunk/ asterisk-php-api

Originating a Call

Once you’ve got it all ready you need to start your new file thats going to make use of it.  In this example I’m creating a simple dialler called: “call.php” which will take two GET variables, with one being the callee and one the caller.

 '192.168.1.5',
  'port' => '5038',
  'auto_connect' => true
);

//Initialise
$am = new Net_AsteriskManager($params);

//Login to the Asterisk Manager interface
$am->login('user', 'pass');

//Originate Call is one of the commands available and it causes a call to be made and connected between two endpoints.
$am->originateCall($number, $from, $context, $cid, 1, 30000);
?>

By looking at the comments above you should see how this works and the steps required. If not then leave any comments and I’ll build on the above. It’s sometimes difficult to know what people already know so apologies if this is too simple or complex. :)

Later on I’ll show how to work with queues – adding, removing, listing, etc.

Asterisk Manager API [PHP]

March 15th, 2008

Asterisk LogoAgain with the PHP code! This time its a bit more exciting than a CakePHP component. If you’ve ever used Asterisk – an open source PBX – then you’ll know it comes with a manager interface which enables developers to send commands to the server to help administer the system and its connected peers and channels.

Visit the blog page for more info on the new PHP interface.

CakePHP SMS Component

March 3rd, 2008

CakePHPI started this blog shortly after getting into Python after becoming fed up with PHP.  Then into Rails and it became (sort of) a Rails and Ruby blog.  I’ve now gone full circle back to my old school days of PHP and have been tinkering with CakePHP recently after getting a taste for MVC architecture working on Rails and Django – I’ve been very impressed so far.

Now to the nuts and bolts of the post: I’m releasing a CakePHP component which makes use of the Clickatell HTTP API to send SMS messages.

I’ll soon be putting up a tutorial with examples at the CakePHP Bakery which I’ll link to from this post soon!  Until then here’s the code for anyone who’s interested: Google Code page for Clickatell SMS Component

Comments, suggestions and feedback is very much welcomed.  There is already a large todo list as you’ll see but it will be getting crossed off in the next few weeks.

I’ll soon be releasing a CakePHP component for Asterisk to provide call origination from your CakePHP apps.

Tags: , , ,

Rails Alternatives

January 10th, 2008

After the recent turmoil I thought it may be worth pointing out a few alternatives to the Rails framework. So here’s 4 Ruby-based web framework alternatives for starters:

  • Ramaze – Has no known bugs and claims excellent stability. Thems fighting words! ;)
  • Camping – A ‘micro-framework’, this is incredibly lightweight offering limited features but great efficiency and speed.
  • Merb – One of the frameworks recommended by Zed this started as Mongrel + ERB, hence the name. Its grown to be a very clean and efficient Ruby framework.
  • Hobo – Not a framework in its own right as its built on top of Rails but it offers a raft of extra functionality to ease and speed up development of your projects.

You may also be interested in the following web frameworks in other languages:

  • Cake (PHP) – One of PHP’s most popular Rails alternatives. More verbose than Rails but providing much of the same functionality.
  • Symfony (PHP) – This is becoming increasingly popular with employers looking for experienced PHP developers.
  • Django (Python) – Hugely popular Python framework and although not the first its overtaken veteran frameworks like Turbogears to be the most popular Python in the box.
  • Turbogears (Python) – An older Python solution which is actually a jumble of technologies stuck together.
  • Sails (Java) – One of the many Java frameworks with a lot of promise.
  • Seaside (Smalltalk) - The onlySmalltalk based framework I know of. I’d really like to have a gander at this at a later date as one of Ruby’s inspirations was Smalltalk so it’d be interesting to see how the forefathers go about framework creation.

If you’re a fan of statistics, reviews and comparisons then maybe you’d like some of these – about as many web framework reviews as you can possibly want!

Facebook API Wins API of the Year

December 29th, 2007

Facebook LogoIf you’ve never heard of Programmable Web then I suggest you take a look. Its a huge directory of all the major APIs on the web open for development. They’ve decided to award the Best API of the Year to the Facebook site. It won based on its openness, audience, money-making potential, viral features, modularity and metrics.

This got me thinking of ideas to put into a new Facebook app but before I jump in at the deep end I’m going to start small with a few quizzes that can plu gin to my existing sites then build from there.

Interesting side note for Ruby/Rails developers: There is an API interface for you to with rFacebook.

Failing that you could just get someone else to do it for you by getting one of the many Facebook Developers to do it for you.

10 Free SVN & Project Hosting Services

September 20th, 2007

Gears

UPDATED: As of Jul 10th 2009

Open Source seems to be exploding all over the place at the moment and with online services increasingly jumping on the free offerings its been fantastic for developers wanting to host, manage, flaunt and communicate their projects online. Here’s a rundown of 6 free SVN hosting and project management offerings I like the look of.

Unfuddle

Nice name and nice site. Very web 2.0 and slick with project tracking such as issue tickets, source control, time tracking, milestones, etc. The free package only comes with 200Mb and restrictive user allowances (1 per account) and only one project. This makes them the stingiest of the group. This is reflected in their price-resources on paid plans with $99 only getting you 10Gb and 50 projects. Compare this to $59.99 at Codespaces for the same space but unlimited projects.

Pros: best interface, great features, Git support.

Cons: high price, low resources, tiny free account.

CodeSpaces

They have a hefty 500Mb for 2 free users per account and they have a good range of prices starting from $9 per month for 4-man teams upto $59 for unlimited.

Pros: nice interface, good pricing, active and involved developers.

Cons: Not as many features as the ‘big-beast’ Assembla.

Assembla

Part of a large and feature-packed service full of project management features as well as basic 200Mb of SVN hosting. It even has a jobs board but the project hosting comes with wiki pages, blogs, etc. The free package has all of this but lacks phone supports and is only for open source projects.  They have VERY competitive prices starting from $3.

Pros: packed with features, reliable, supports Mercurial.

Cons: pricey in the higher plans.

OpenSVN

One of the first to release free SVN hosting and starting to show its age with very barebones features. They had a major failure in backup and restore last year which causes some worry about their reliability. So when I say “free SVN hosting” I really mean just that!

Pros: unlimited space, unlimited projects.

Cons: very unreliable, no features!

XP-Dev

This is a very no-frills setup but they have one killer feature: Private SVN repo hosting – FOR FREE!!  Made for agile and extreme programmers this doesn’t have a lot of the features inherent in other services but thats just fine.  Its also got an unlimited repo limit.

Pros: unlimited repos, free private hosting

Cons: Only one paid option, very few features.

Bounty Source

Still going strong after I first mentioned it back in June Bounty Source offer your basic SVN along with a wiki and CMS for managing your projects online presence as well as a task tracker. Bounty Source have a unique feature though that enables a developer to be paid for the work they carry out on user feature requests. Something I really like the look of – all I need now is an open source project people are going to pay me to finish!

Pros: bounty system helps devs get paid to work.

Cons: no paid option, looking old, falling behind in features.

SourceForge

Like an old grandfather clock this has been around years and although very reliable its showing its age. They tried to spruce it up with some Web2.0 gradients and curves but you can’t scrub out the moldy smell from that interface and features-set.

Pros: reliable, well established.

Cons: very intrusive ads, pain to use.

Google Project Hosting

They seem to have taken a lot of the old school methods of project hosting from SourceForge. Unfortunately as mentioned earlier they’re looking old and although Google looks much cleaner its features still lack the richness that the smaller providers have who’ve gone all out on innovation while Google remains formulaic. Google also don’t provide paid private hosting. Its all open source here.

Pros: reliable, clean interface, good features, supports mercurial

Cons: no private paid options, open source only

Comparison Table – Free Accounts

Metric Unfuddle Code Spaces OpenSVN Bounty Source XP-Dev Google SourceForge
Project/Repo 1/Unlimited[1] Unlimited/Unlimited 1 Unlimited 5 Unlimited[4] Unlimited
Space 200Mb 50Mb Unlimited N/A[3] 300Mb Unlimited[4] Unlimited
Wiki Yes Yes No Yes No Yes Yes
Tracking Yes Yes No Yes No Yes Yes
Browser Yes Yes No Yes No Yes Yes
  • [1] Unfuddle allow one active project but unlimited numbers of repos within it.
  • [3] They state nowhere on their site about limits to project size.
  • [4] Google claim in their terms that there’s no upper limit but they reserve the right to impose one.

PHP is an Auto-Mountian Bike

August 18th, 2007

After someone posted this article to the dZone site they were quick to spot that it missed one crucial language from the list: PHP.

So here’s my take on what PHP would be like if it was a car:

PHP was a mountian bike that got crow barred into car-dom.  Its had a lawn mower engine strapped to its rear wheels and a turbo made from washing machine ducting kitted round the front.  To keep it all going a set of stabilisers and prayer beads have been chucked on.  It’ll get you from A to B but its not as reliable or friendly as that Python and Ruby model that just hovered past.

Yahoo UI – New DataTable Widget

February 27th, 2007

When I first looked at YUI when I was on the hunt for a simple yet powerful Ajax library I cast it aside in favour of Dojo. Which back then I preffered due to its tag parsing as opposed to pure JS implementation of its various widgets.

However, now I’m getting a bit more into the JS side and it doesn’t feel so daunting I decided to take another look at YUI – and I’m very glad I did. Because since my last foray into this Ajax library they’ve added some interesting new features and widgets (in beta stage).

The one I’ve found to be most useful so far has to be the DataTable. Of all the Ajax tables and grids out there that I’ve seen none come close to Yahoo’s DataTable in its speed (happy to deal with 00000’s of records), efficiency, power and functionality. Pagination, sorting, row number, infinite scrolling of data, inline editing, nested columns, row selection, data sources (accepts JSON, XML & CSV) are all very flexible allowing for an immensely powerful widget that puts Dojo’s table to shame.

After some minor niggles I managed to get my YUI DataTable up & running (with the help of Jenny and Nate at the YUI dev list). My cut down example is here in case anyone needs just another example to make something click.

This was decalred in a seperate JS file (as were all my tables) which was then included in the page.

var itemDataTable;
function exec_item_table(id){
var itemColumnHeaders = [
{key:“item_id”, text:“ID”, sortable:true, type:“number”},
{key:“code”, text:“Code”, sortable:true},
{key:“name”, text:“Name”, sortable:true},
{key:“description”, text:“Desc”, sortable:true},
{key:“qty”, text:“Quantity”, sortable:true},
{key:“unit_cost”, text:“Unit Cost”, sortable:true}
];

var itemColumnSet = new YAHOO.widget.ColumnSet(itemColumnHeaders);

// Point to a local or proxy URL
var itemDataSource = new YAHOO.util.DataSource(“http://localhost/bms/bms_ajax.php”);

// Set the responseType as TEXT
itemDataSource.responseType = YAHOO.util.DataSource.TYPE_TEXT;

// Define the data schema
itemDataSource.responseSchema = {
recordDelim: “\n“, // Record delimiter
fieldDelim: “,”, // Field delimiter
fields: [“item_id”, “code”, “name”, “description”, “qty”, “unit_cost”] // Field names
};

// Configure pagination features
// The following object literal reiterates default values
var initialRequest = ‘do=items&id=’+ id;
var itemConfigs = {
initialRequest:initialRequest,
pageCurrent: 1, // Show page 1
rowsPerPage: 25, // Show 500 rows
startRecordIndex: 1, // Start at first Record
pageLinksLength: -1, // Show all page numbers in direct links
rowsPerPageDropdown: [10,20,50,100],
singleSelect:true
};
itemDataTable = new YAHOO.widget.DataTable(“itemContainer”, itemColumnSet, itemDataSource, itemConfigs);
itemDataTable.subscribe(“cellClickEvent”, itemDataTable.onEventSelectRow);
}

This being the PHP side which generates the CSV then echoes it out for the JS to pick it up.

$csv_data = ”;
$sql = “SELECT * FROM fran_invoice_items WHERE invoice_id=”.$_GET[‘id’];
$res = mysql_query($sql);

while($row = mysql_fetch_assoc($res)){
$csv_data .= $row[‘item_id’].“,
“.$row[‘code’].“,
“.$row[‘name’].“,
“.$row[‘description’].“,
“.$row[‘qty’].“,
“.$row[‘unit_cost’].“\n“;
}

//You need to trim the last "\n" otherwise the DT won’t render.
$csv_data = trim($csv_data);
echo $csv_data;

Some important points I mentioned on the mailing list are:

  • At the moment there’s no way of having the page numbers for the table at just the top or the bottom. They’re always at both ends. I made a feature request for this but there was a workaround offered by one of the members on the list which you can find here.
  • Whenever I had a column with the “key” as “id” it seemed to assume I meant the YUI generated row ID rather than the fieldname of my data field I sent using CSV. A simple name change sorted it but just a heads up if you try using “id” as a key name in your table – don’t. Give it a name like: “thing_id”.
  • Refreshing the table data after making an edit to the records can be done by re-instantiating the table.