PHP vs. ColdFusion

PHP vs. ColdFusion

In my years I’ve found myself actively writing in several different languages. I’ve written full applications in ASP.NET, PHP and ColdFusion. My current primary languages are PHP and ColdFusion.

Throughout the years I’ve grown really fond of ColdFusion. In this article I’m going to explain the benefits & cons of ColdFusion over PHP.

Benefits to PHP

  1. Widely supported and has a huge community of people willing to help and answer questions.
  2. Open source.
  3. A vast amount of open source scripts available.
  4. A large number of shared hosting providers that are willing to offer hosting for very low cost. For instance $3.00 – $10.00/month.

Cons to PHP

  1. Is not the easiest language to learn.
  2. Development time can be very time consuming as everything is syntax based and requires a lot of code.
  3. Server settings are made through a text file called php.ini which can be a hassle and can make issues difficult to diagnose.
  4. Servers are typically apache, which often causes issues with file / folder rights.
  5. Doesn’t have a very good template system compared to ColdFusion’s custom tag based templates.

Benefits to ColdFusion

    1. Very easy to learn compared to PHP.
    2. Extremely easy to read compared to PHP.
    3. Writing ColdFusion applications require much less code compared to PHP.
    4. Coding applications is much less time consuming as ColdFusion is much more Robust than PHP.
    5. Although the Adobe ColdFusion server is not open source, there is an excellent ColdFusion alternative. http://getRailo.org/
    6. The ColdFusion administrator is very easy to use and has a nice User Interface.
    7. ColdFusion has something called Custom Tags, which makes the managing and accessing of website templates a breeze.
    8. Very easy to use coldfusion OOP functions. Also allows for .NET and Java integration.
    9. Integrates very well with Flex.
    10. Extremly Robust with a vast amount of built in javascript packages like cfgrid, cfwindow and cftooltip. Also coldfusion has built in functions to allow ajax binding extremly simple.

Cons to ColdFusion

      1. Community is not as big. However, although the community isn’t as big, I think that you’ll find more ColdFusion programmers per capita than php.
      2. Some people don’t like how easy to learn and read ColdFusion is because they claim that it’s so easy to code that it’s not like programming it’s more like talking about code. Which is probably true.
      3. Those who use Adobe’s ColdFusion think that it’s expensive. Those who use Railo think it’s free.

EXAMPLES

Want to see some code examples? I’ll show you how robust ColdFusion really is.

The PHP code below, will return the columns firstname, lastname from the Friends table.

<?php
//
$con = mysql_connect("localhost","username","password");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT friendId,firstName,lastName,nickName FROM friends");

while($row = mysql_fetch_array($result))
 {
 echo $row['FirstName'] . " " . $row['LastName'];
 }

mysql_close($con);
?>

Now look at the Coldfusion Example

The ColdFusion code below, will return the columns firstname, lastname from the Friends table.

<cfquery name="getMyFriends" datasource="peter">
SELECT friendId,firstName,lastName,nickName
FROM friends
</cfquery>

<cfloop query="getMyFriends">
#firstName# #lastName#
</cfloop>

Isn’t the ColdFusion code just so straight forward to the point and easy to read?

This is just a single example of hundreds, no thousands of reasons of why I personally think that ColdFusion is better than PHP.

Source : http://paulalkema.com/post.cfm/php-vs-coldfusion

34 responses to this post.

  1. Dave Ferguson – Jul 5, 2010 at 10:18 AM

    Very nice comparison. It is nice to see a side by side code example to illustrate things. –Dave

    Balas

  2. J.J. Merrick – Jul 5, 2010 at 10:38 AM

    I too have used ColdFusion for almost 11 years now and have done a lot more PHP in the last couple of years. I think there are some issues with your comparison. To say that PHP doesn’t have Custom Tags is true… but only because it isn’t a tag based markup… it is script based. They both have the ability to create User-Defined functions and they have basically the same syntax. Also yes the PHP code to connect to MySQL is more verbose it is because there is no concept of “datasource” in PHP. You are not showing the steps you have to go to get the datasource created in the admin so that you CAN run the code. You also are doing some error catching in the PHP code which you are not doing in the CF code… something that doesn’t have to be in either but if you add it to one you need to have it in the other. Also once again if you did this in CFscript it would be much more verbose and about the same amount of PHP script code. I think what it really comes down to is the jobs available. There are simply more PHP jobs out there. it’s almost like if you were a mechanic that only worked on MG’s… you probably wouldn’t be in high demand but people that did need you would pay a lot of money for your services but finding them is going to be harder. PHP is the Ford mechanic… lost of people are going to use you but you might not get as much money… but the work will always be there. I have really enjoyed working in PHP lately but a lot of it is because the projects that I am getting are just more fun. A lot of the CF projects that I do are older legacy enterprise systems where I go in and patch things up and keep them humming along and that just isn’t as fun as the PHP projects I am getting. In the end of course CF is going to be my go to… mainly because I have used it for so long that I can work circles around PHP in it. I can diagnose complex issues and be confident in creating high-available critical systems… but that doesn’t really mean PHP is any better then CF or vise versa.

    Balas

  3. Justin Scott – Jul 5, 2010 at 11:10 AM

    Just a couple of things. First, your PHP block has some error handling and the ColdFusion block does not, so it’s not a perfect comparison. You might want to put a CFTRY/CFCATCH block around the CFQUERY to catch a connection error just like the PHP code, or remove that portion from the PHP block to be more fair. Also, with the ColdFusion code, switching from one database platform to another is a lot easier. The CFQUERY tag and its related sub-tags and functions are not tied specifically to any one database platform like they can be in PHP. Just change the datasource settings in the administrator and you’re talking to another database without any code changes (notwithstanding the actual SQL changes that may be needed in either language).

    Balas

  4. Jose Galdamez – Jul 5, 2010 at 11:24 AM

    I only started dabbling with PHP for the first time a couple of weeks ago. I’m slowly getting used to the syntax. For now my biggest beef is having go store entire blocks of HTML within string variables. I’ve come up with a few semi-elegant workarounds where I can have the HTML by itself similar to CFML, but I’m still not at the point where I can say I’ve found a templating approach that beats CF’s custom tags. One way to perhaps beef up this comparison would be to show CF9’s new way of querying the DB using ORM. To be fair, there could be a PHP example that uses a similar approach that doesn’t require using inline SQL.

    Balas

  5. Legacy coldfusion guy – Jul 5, 2010 at 1:16 PM

    What does this really mean….”more ColdFusion programmers per capita”

    Balas

  6. WilGeno – Jul 5, 2010 at 3:56 PM

    I’ve been programming with ColdFusion since 1998. While I like to see these sorts of comparisons you should at least get them correct. I’ve also programmed c/c++, assembler, FORTRAN, PERL, BASH, PHP, ASP, SQL and more. Your claim that ColdFusion is easier to read. Well, maybe. You are used to tags. Others are used to scripted languages and those are just as easy for them to read as CFML is for you or me. And with any language the person writing the code can be and clear and concise or as sloppy or obscucated as they desire. I’ve seen clear concise PHP and funky nasty CFML over the years. I’ve also written some fairly complex PERL and RegEx that some find clear and others thought I fell asleep on my keyboard. The ease to read and understand comes down to your training and the method of writing that the codes author used. You claim that PHP is not easy to learn. That too depends on your knowledge of programming. I learned PHP in the same amount of time it took me to learn ColdFusion. Just a couple of days. But then, I’m a trained programmer of many languages and all I need to learn is syntax for the most part. If you mean ColdFusion is easier for non-programmers to learn then say that. Because that would be the truth. Error handling. ColdFusion does a lot of this for us and PHP leaves it all to you. If you are going to do a lot of PHP learn about ‘or’. See my example below. Datasources area managed by the server in ColdFusion. PHP does not have them. However, I’ve programmed around this by using proper MVC you can create the connection to the DB once and then execute all the queries you need for the current request then close the db connection at the end. Php.ini – yup, that exists. So does jvm.cofig for ColdFusion. Gotcha, most people don’t even know about this or the myriad of other text config files for custom high load ColdFusion configurations. Servers for ColdFusion are typically IIS – (I think that is still the case). IIS is a security nightmare. I much prefer Apache to IIS any day. Even on Windows. Many of the previous comments are correct also. While I hope to never move away from programming with ColdFusion, I’ve made programming my life thus I know multiple languages and the next language is just learning the syntax. There are valid comparisons to make between ColdFusion and any language. It does not help us in the ColdFusion Community when faulty comparisons are made. More correct PHP code:

    Balas

  7. WilGeno – Jul 5, 2010 at 4:00 PM

    Lets see if you allowed the code to be posted like this. More correct PHP code: $con = mysql_connect(“localhost”,”username”,”password”); mysql_select_db(“my_db”, $con) or die(‘Could not connect: ‘ . mysql_error()); $result = mysql_query(“SELECT friendId,firstName,lastName,nickName FROM friends”); while($row = mysql_fetch_array($result)) { echo $row[‘FirstName’] . ” ” . $row[‘LastName’]; } mysql_close($con);

    Balas

  8. David Boyer – Jul 6, 2010 at 3:49 AM

    @Paul, I live in both Coldfusion and PHP worlds, although mostly in the CF side of things lately. Thought I’d point out that some of your “Cons” about PHP aren’t as bad as you think. Zend offer a free community edition and a paid commercial version (with extra features) of Zend Server. This is a lovely package that comes with Apache or hooks into IIS. The best thing about it is the CFIDE/Administrator like web interface for configuring all the PHP options. No more messing with that php.ini file. Plus it works wonderfully well with IIS and upgrades are quite painless. I don’t think it’s easy to compare CF and PHP. You mention that PHP doesn’t have a good templating system compared to CF and its tags. CF is awesome and makes things simple and easy from the get go. PHP is more raw initially but has more choice available, there are loads of templating systems available for PHP, you just have to pick the one you like. If you wanted to compare PHP against CF properly, I’d suggest comparing PHP and a framework against CF.

    Balas

  9. Jose Galdamez – Jul 6, 2010 at 8:10 AM

    I would like to add that it’s tough to read these comments as they were originally typed because the paragraph breaks aren’t converted into p tags. I’ve noticed everything gets bunched up into one long paragraph. CF’s ParagraphFormat() is an easy fix for this. http://www.cfquickdocs.com/cf8/#ParagraphFormat

    Balas

  10. Rodrigo da Rosa Elesbao – Jul 6, 2010 at 7:30 PM

    Very poor article, i like both, CF and PHP for many reasons, but on this article you mentioned just the advantages of one language and completely forgot why PHP have so many developers, community and easy integration in any server. So i suggest you rewrite your article based on real facts not a fantasy text like this. CF is gooder than PHP, but no one can say that CF can beat PHP today.

    Balas

  11. AntonioCS – Jul 22, 2010 at 6:00 AM

    There are now many many php frameworks that help with creating cleaner code. Your code example is really lame, as previous posters have pointed out, you didn’t add error code to your coldfusion example. PHP now has PDO witch enables you to switch from mysql to mssql or any other db you want without changing the code, just the connection parameters. If you prefer coldfusion don’t make articles like this. This is not a fair “versus” you are biased towards coldfusion it’s clear as day.

    Balas

  12. Paul Alkema – Aug 10, 2010 at 8:23 AM

    Some of you have pointed out that there are php frameworks that can help make code cleaner or add features ect. It should be noted that when I wrote this article it was to compare php and ColdFusion out of the box, there are many frameworks for ColdFusion like ColdBox, ColdSpring and CFWheels and I don’t think it’s a fare comparison to compare ColdFusion out of the box vs. php with frameworks. It has also been mentioned several times that in my php example I was has error handling where in the ColdFusion example I do not. The reason I was doing this is because from what I’ve learned about php it’s a best practice to have error handling when creating database connections. My php example is extremely similar to the example at w3school.com. http://www.w3schools.com/php/php_mysql_select.asp. In ColdFusion however, it is not a best practice to try to catch connections if they fail. http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_17.html.

    Balas

  13. J Garvey – Aug 19, 2010 at 8:47 AM

    I am looking for overall security information on the different platforms for a business case I am writing. Can anyone share with me comparative thoughts on the security of Apache/PHP, Coldfusion and .net configurations (it would help a lot if you could document where you are getting your information from. Thank You.

    Balas

  14. ryantxr – Sep 12, 2010 at 4:26 PM

    No serious PHP programmer in his right mind would write code like that. It is super easy to create a small wrapper class to contain the database connection. Takes 15 mins if you are creating it from scratch.

    Balas

  15. ryantxr – Sep 12, 2010 at 4:29 PM

    PHP has a template engine. It’s called PHP. It is as fast as it gets because it is built into PHP. Take a look at how CakePHP, Zend Framework and Code Igniter use this feature. Additionally, Drupal, Joomla and WordPress all use PHP as a template engine.

    Balas

  16. ryantxr – Sep 12, 2010 at 4:37 PM

    To Jose Galdamez: There should be no need to wrap blocks of HTML into strings. Use HTML as you normally would and use PHP to output the data you need.

    Balas

  17. Paul Alkema – Oct 19, 2010 at 11:20 AM

    @ryantxr, I pulled my php example straight from w3cschools.com in their example of how to make basic query statement. I pulled my ColdFusion query from the ColdFusion documentation website in their example of how to make a basic select. Both of these I did change variables to make them more consistent with each other for readability. http://www.w3schools.com/php/php_mysql_select.asp http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html “PHP has a template engine. It’s called PHP. It is as fast as it gets because it is built into PHP.” I’ve seen and used some of these “template engines” your speaking of. I haven’t found any of them even close to as easy as ColdFusion’s custom tags. If you show me an example of how it’s easier perhaps you could convince me but as far as I’ve seen nothing even comes close to ColdFusion’s custom tags which is also built into ColdFusion and requires no additional downloads. Again, I’m speaking ColdFusion out of the both with no additional downloads, if you compare ColdFusion vs. php with Zendframework or CakePHP that’s not a fair comparison as ColdFusion has frameworks as well.

    Balas

  18. geekis – Jan 21, 2011 at 5:21 PM

    Your comparison is quite biased. You fail to mention how much Coldfusion costs to use while PHP is free. Coldfusion currently costs $8,000 to purchase. Furthermore, you are not comparing the two code blocks fairly. Your Coldfusion code uses SQL queries and connections contained elsewhere, which is still code. All you have done is abstracted it away and used it via the cfquery tag’s parameters. Why not put the connection and query elsewhere in the PHP example? Coldfusion requires Java to use while PHP uses its own engine. Lastly, I never understood the utility of tags. It adds extra, unnecessary code. I don’t like having , , etc numerous times. A closing brace is much cleaner.

    Balas

  19. LeAlba – Jan 21, 2011 at 8:41 PM

    All people deserve good life time and http://bestfinance-blog.com/topics/home-loans“>home loans or short term loan would make it much better. Because freedom is based on money state.

    Balas

  20. Larry Lyons – Mar 31, 2011 at 2:35 PM

    geekis – Jan 21, 2011 at 5:21 PM wrote Your comparison is quite biased. You fail to mention how much Coldfusion costs to use while PHP is free. Coldfusion currently costs $8,000 to purchase. ———- Perhaps you were correct 5 years ago, but not now. There are two very powerful enterprise ready alternative open source CF engines, Railo and OPen BlueDragon. Secondly if you are going to compare CF Enterprise (~$3000) to PHP at least do a realistic comparison, with Zend Production Server. The price for that one ranges from $4,790.00 to 6,890.00 according to the Zend on-line store. If $3000 is going to break your enterprise, then I think that the company in question is in deeper trouble than you think. Moreover, as I mentioned both Railo and Open BlueDragon are free and open source solutions. Cost: $0.00. So using your own biased PHP centric comparison, CF 0 – $3000 vs just under $7000. Want to try another one?

    Balas

  21. Quintin Bressler – Apr 24, 2011 at 2:39 PM

    Well, I would consider PHP to be more for programmers…If you learn PHP, the syntax is very similar to other languages…So, migrating from one language to the next is generally pretty simple. CF is definitely easier than PHP since all of the functions are compiled down to java for you…But I do agree about the job market. There are way more job openings for php developers than CF developers. In fact, most shops that run Coldfusion will easily hire a PHP developer since the transition of learning CF will generally be simple for the PHP developer. just my 2 cents

    Balas

  22. From A Client Perspective – May 2, 2011 at 9:26 AM

    Unfortunately, there is a much larger issue with CF: cost. And it is this very reason than CF is dying. Before anyone gets upset, let me explain where things are. As part of the costs for developing CF, particularly when approaching a client with a dedicated server (meaning they have to pay licensing for everything) it is impossible to sell the $7,500 cost of the license for the Enterprise version to a client because they have to pay for it! Sadly, the Standard version at $1,300 is not a compelling option since the value of CF really lies in the Enterprise version (there are other arguments against this stance, but I deal with this every day and that’s where it nets out – Railo, or the like is not an option because we cannot support it). Some may argue here that the savings from CF to PHP is the same as the license and that CF has many built in functions that make it superior to PHP and save costs. The feature set and costs saving for small projects is true, but clients want an overall ROI and this means not having to worry about supporting an application five years from now. Or ten. Enterprise clients see more value is spending a little more for PHP because they know the world out there can easily and cost effectively support it. Their entire IT staff or their outsourced IT company can die in a plane crash and the very next day they can find some decent PHP people. CF? Not so much anymore. In fact, we are trying to hire CF people in NYC and we’re having a tough time! Forget code and convenience and focus on cost. CF is becoming the FORTRAN of this century. When Adobe lets CF go zero cost on it’s servers CF will become a real threat.

    Balas

  23. Pal – May 20, 2011 at 6:11 PM

    @From A Client Perspective – You are a an idiot. After reading “And it is this very reason than CF is dying…” Since you made a statement with absolutely no basis in fact I ignored the rest of your rant. CF is bigger now and has grown in size and user base every year since inception; one of the old DB scripting / web dev language in the industry. As a PHP and CF developer I have plenty of opportunities in both language and the number of CF opportunities for me has grown dramatically in the last three years. To say the CF is ‘dying’ is the statement of an idiot and very irritating to say the least. I have been using CF since version 1.5b an I also use PHP. My experience with people use make statements like the above are people who only use PHP and have never used CF.

    Balas

  24. Mortgage Calculator – Jun 14, 2011 at 9:56 AM

    Hi Get this comment all the time. Click the “reviews” tab if you want to have your own page on this site. Regards Sam

    Balas

  25. Web Developer – Jun 27, 2011 at 5:53 PM

    I read here something like “There is no template engine for PHP.” or “PHP is the template engine!”. These statements are both wrong! With a template engine you want to avoid that _any_ PHP code shows up in between the HTML. Therefore is PHP not a template engine itself, even you can mix PHP in between HTML. And yes, there are Template engines for PHP: Smarty is a very good one which is OO and provides output logic. With MODx you have a really cool MVC framework, where you can use plugins for output logic. You can even write your own ones. The these are very powerful due to caching and/or compilation features. Clean separation between HTML and PHP is the key! Mixed in tags are not good for collaboration and maintenance. I strongly suggest to check out these two systems. Here are the links: http://www.smarty.net/ http://modx.com/ I am not a CF guy, but very experienced with PHP. So I have a Question: Is there a way to write CF without mixing it with HTML?

    Balas

  26. Tub CoversTub Covers – Jun 28, 2011 at 10:24 AM

    Hello Good stuff! Keep up the work and I’ll keep coming back for more! Regards Caris

    Balas

  27. Justin Adie – Jul 14, 2011 at 11:13 AM

    isn’t the point that coldfusion is an abstracted tag language? so a fairer php comparison might be to use PDO? $pdo = new PDO(‘mysql:host=localhost;dbname=testdb’, ‘username’,’password’); foreach($pdo->query(“SELECT friendId,firstName,lastName,nickName FROM friends” , PDO::FETCH_OBJ) as $row): echo $row->firstName . ” ” . $row->lastName; endforeach;

    Balas

  28. Justin Adie – Jul 14, 2011 at 11:16 AM

    (lousy comment parser) and of course that could be made even shorter $pdo = new PDO(‘mysql:host=localhost;dbname=testdb’, ‘username’,’password’); foreach($pdo->query(“SELECT friendId,firstName,lastName,nickName FROM friends” , PDO::FETCH_OBJ) as $row) echo $row->firstName . ” ” . $row->lastName;

    Balas

  29. Joel Dies – Aug 3, 2011 at 3:09 PM

    @Larry Lyons You mention that Zend cost 4000-7000$ roughly and CF is free. Remember he is comparing out of the box from the original sources. If you compare php from php.net it is free, as if you get cf from adobe for enterprise useage it is 600$ shy of 8000$, and the standard edition is 1300$. Remember this is out of box, no frameworks, no extra garbage. Getting CF from another source would be like grabbing a *AMP package and comparing that. To say that grabbing a free package if CF from a third party brings in the option of third party packages. I can download a LAMP package and be setup and ready to use in about 5 minutes after downloading it. I dont see that happening with CF, but I do not use CF but I have converted some messy CF code to php.

    Balas

  30. Paul Alkema – Aug 9, 2011 at 1:41 PM

    Comparing Adobe ColdFusion and Railo ColdFusion isn’t the same as comparing php on apache and LAMP because LAMP run’s it’s php on apache. Railo is ColdFusion. Also, if you download Railo, you can most definitly run it right out of the box within minutes. Actually, railo doesn’t even require an install to run it, you can just download it and click on the executable and it will run right away.🙂

    Balas

  31. websiteop – Aug 23, 2011 at 7:03 AM

    I don’t think one is really better than the other, I’m a PHP guy personally. The thing I like about PHP is that its of course open source and it is easier to use the programming skills from PHP to switch to other languages like Java, Python. But , again CF has it uses for being a very high level language.

    Balas

  32. JlaDesigns – Aug 24, 2011 at 5:49 PM

    I’m not entirely convinced anyone here actually sees the comparison objectively. As specifically mentioned by Paul, Cf is a far more succinct markup than php. There’s not mention in the examples above of the requisite connection strings for Coldfusion, because the interface functions more as a ‘wizard’. Select datasource, name datasource, point to datasource, verify, done. I use both markups – and some other fun (asp, asp.net) and frankly, there are lots of tools in out there for all of them. Where the present comments fail is understanding which tool fits the job at hand. Not to mention, as browser development improves, the need for server side programming declines… We’re quite a few years from Mozilla doing our work for us, but ignoring advantages of the languages’ respective differences is the new FORTRAN. Be a better developer by learning about development, not proofing the code samples here.

    Balas

  33. JlaDesigns – Aug 24, 2011 at 6:00 PM

    @AntonioCS, your website has ‘Portfolio’ spelled incorrectly. Smart.

    Balas

  34. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am anxious about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can import all my wordpress posts into it? Any help would be really appreciated!

    Balas

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: