Posts Tagged ‘php’

Tabs vs. Spaces

December 1st, 2009

Every time I’ve seen one of these “vs” posts its gone into great length about the philosophy behind such and such.  You’ll never convince someone based on ‘religious argument’. So I’m going to take a different approach here and state who does what and hopefully the weight of ‘who does what’ will make the point quite clear.

Screw the Scientific Method!!

Language/Organisation Spaces Tabs Reference
PHP Pear * [1]
Zend (PHP) * [1]
Python * [1]
Ruby * [1]
Java * * [1]
.Net * [1]
C# * [1 Philips (PDF)] [2 - Microsoft]
Lua * [1]
Erlang * * [1]
Object Pascal * [1]
Adobe Flex * [1]
Ada 95 * [1]
Mozilla (Javascript) * [1]
Mozilla * [1]
Google * [1] [2]
Mono Project * [1]
Webkit * [1]
NASA * [1]
Apache (C) * [1]
Linux Kernel * [1]
Gnome * [1]
KDE Libs * [1]
Joomla * [1]
Wordpress * [1]
Zope * [1]
Django * [1]

Notes:

  • Tabs may be rendered differently on different editors and systems.  So they make for less friendly code sharing.
  • Its interesting to note that the ones using tabs all have histories of mental instability, cannibalism, Morris Dancing, witchcraft and heresy.

Clear win for Spaces, which happens to be what I use.

Switching From Rails to Django: Why?

November 15th, 2008

Rails is crap.  There – I said it.  Apologies to the geek with a peanut dick but it just sucks really bad.

Compared to PHP – Rails is Great

Yeah it is great – its epic in fact.  But then again that isn’t very hard is it considering how shit PHP is?

Stop Stealing Ruby’s Limelight

The reason people love Rails is because of Ruby.  It pisses me off when I hear people getting pissed off with having to learn Ruby so they can use Rails.  For crying out loud!!  Ruby is the foundation, cause, Nu(n), beginning, soul, reason for Rails existence.  All of those funky little things that Rails can do are entirely due to Ruby.  Ruby is an amazing language and Rails is an insult rather than a blessing to it.

Rails and Mongrel = Unstable

Every time I get into an argument regarding Rails’ reliability it comes back to: “It must be your code”.

Well fair enough.  Lets say my code is the reason that all my Rails sites fail at least once a week.  Or maybe its my setup, or server config.  Maybe I’m not using Mongrel right.  I’m a dumb fuck who can’t use Rails…

But…

This “dumb fuck” can setup and manage multiple Django sites without issue.  Without hassle.  Without self delusion.  Without restarts every fu*king week!  This “dumb fuck” has had 3 Django sites running for the past 8 months with no downtime.

Okay – so I could setup scripts to kick Mongrel back in when it falls over.  I could manage or code better.  I could do many things.  But why the fuck should I?

I think a good analogy is this:

  • Rails = Windows
  • Django = Apple

You see – Django Just (fucking) Works.  Like a Mac.  Nice and simple.  Reliable.  Consistent.

Rails needs hacking and bollocking around with until it settles.  Then you need to faff some more when it plays up.  Sounds familiar doesn’t it?  Just like Windows.

But All the Cool Kids Use Rails

Yeah – all the cool kids use Rails.  Do you remember that all the “cool kids” at school were normally the biggest dicks in the school?  They were the thickest, most aggressive, most lacking in self confidence and respect.  They followed a ‘leader’ blindly because they were too weak to follow their own path.

The Rails community comes in two parts:

  • A core of heavily invested super-egotistical fat-assed vermin that need it to continue in order to make money training, publishing, etc.
  • A huge cloud of numb nuts who don’t know how to program but jumped on the Rails bandwagon to be cool.  These people invariably make themselves look like idiots when challenged.

Lets look at some real technology leaders:

Google - they use Python for the majority of their systems as well as choosing Django templates for its Google App Engine.  They also rapidly built Django support into it.  Rails hasn’t even hit the radar.

Rails Has Huge Support From The Tech Industry

Similar to the above but I knew you’d never read through anything longer than a few paragraphs so I put this shit here.

Rails attracts disaffected, immature hippies and divs.  No major company has embraced Rails for anything serious.  The only ‘companies’ that have embraced Rails are the fluffy-bunny brigade of non-companies.  They make money but they’re the technological equivalent of the Care Bears:

  • Twitter – for inane bullshit.
  • 43 Things – You put the things you want to do in life.  Personally?  I just do them!
  • Amazon – I almost shit myself when I saw this.  Until I read the details about it:
  • UnSpun is a new service from Amazon that puts workers from the Mechanical Turk and the UnSpun community at work finding the top, best, favorite things in any category.
  • Sounds like a world beater.  Really taking over Amazon there aren’t you.

Django Copied Rails

No, it didn’t – that was my controlled response to this ridiculous statement.  My natural response had a lot more ‘beating YOU in the face for thinking such a thing’.  Django and Rails were born from very different worlds and purposes.  Neither copied the other.  Although multiple projects have spawned in the Rails community to copy the Django admin interface.  Jealous, much?

Discuss?

Comment or email me.  If you disagree I’ll likely mock you.  If you agree I’ll send a digital kiss.

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: , , ,

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.

PHP Frameworks Review

March 29th, 2006

Browsing the del.icio.us pragramming tags earlier today I came across an interesting review of some of the major PHP frameworks floating around at the moment. It should be noted though that there seems to have been some unfair omissions of CakePHP’s features in the accompanying chart and review.

Sun’s Gosling on Ruby and PHP

March 15th, 2006

I spotted a recent article while on the Riding Ruby blog in which James Gosling of Sun – aka: “Father of Java” made extensive comment regarding Java’s placing with Ruby, PHP and other platforms.

“PHP and Ruby are perfectly fine systems, but they are scripting languages and get their power through specialization: they just generate web pages. But none of them attempt any serious breadth in the application domain and they both have really serious scaling and performance problems.”

Scaling and performance problems have been shown to be null and void when Friendster switched from a Java platform to a PHP platform and had a noticeable speed improvement – Friendster is no shrinking violet, once boasting the largest social network on the web.

Scripting Languages?
That comment jars a little as its a far out dated term normally reserved for cheap pot-shots. I’ve had numerous discussions with Java advocates in which Ruby, Python and any other dynamically typed language has been dismissed as a meer scripting language. It doesn’t look like I’m the only one either as Ryan Tomayko at Lesscode.org seems to have paid comment to Goslings post in quite some depth and I recommend a read!

UPDATE: The Artima Developer forums have a thread sicussing this topic available here.