Archive | CFML RSS for this section

Why Coldfusion / CFML has its place and is worth to learn it

I actually never indulge in conversations why one programming language is better then another, because what is right to you, does not automatically mean, it is right for someone else. So, for me ColdFusion, or as we call the language itself – CFML, works very well.

Nevertheless, in this post I like to clear up some confusion that has been around. I can see where the confusion comes from as Coldfusion has gone from Allaire to Macromedia and is now “in the hands” of Adobe.

In any case, here are some reasons why CFML is still worth for you to learn.

  • CFML is open source and yes you can use it for free. I guess, many people are put off by the fact that Coldfusion has had a big price tag on it in the past. True, given the nature of PHP, Java, Phyton, Ruby, etc. being free, there was actually no reason to shell out your hard earned buck for some application server and on top of it even learn the language. Thanks to the short sighted business decisions of Macromedia and now Adobe or shall we say with the greedy money making mentality of its management, Coldfusion has been faced with a drainage of developers.
    Fortunately, this has all changed with the advent of OpenBD – the first real open source CFML server, followed shortly by Railo, another popular open source CFML server. In other words, to learn CFML and to deploy your applications, is now free and free to be.
  • Write less code. Compared to PHP, Java, C++, even Ruby and Python – CFML allows you to write the same program with much much fewer lines of code. Why would you want spend your precious time writing more code when you can do it for less? As a matter of fact, you can write your application in CFML so efficiently, that the same application written by you alone would probably need a team with Java, Ruby, etc. This is a proven fact.
  • Well designed. The CFML language is well designed and many required functions already exists for you to use. There is no need to write a wrapper for a email sending function. I mean, you don’t even need a framework, to achieve a simple tag like “<cfmail…>”. There is no obnoxious, framework to learn or write functions for this. Compare this to Java, PHP, Ruby, etc. you are very well off with CFML. (again all without a framework)
  • Build web applications fast. Due to the nature of writing less code with CFML and with the built in function, you will be writing your next web application in weeks, instead of months. On top of that, you will have a full scalable enterprise model on your hand to scale when your startup takes off. Heard about the stories of PHP web apps, that had to be converted to xyz language just to scope with the traffic. Again, if you would deploy your web application with CFML and OpenBD, you can deploy on any Java application server (Tomcat, JBoss, Websphere, etc.), connect to any database (MongoDB, H2, Oracle, MySQL, MS SQL, DB2, you name it…) and have your cluster, load balancing, caching setup done.

If you are in for writing less code and building your next web application the fast way, then I simply urge you to give CFML a try. I’m certain that you will get your project done in half the time then in another language. There is simply nothing to loose for you!

 

CFML and Cannot run program “chmod”: java.io.IOException: error=24, Too many open files

Migrating one of my customers the other day, bought up an ugly error when I had to create 2000 directories on one go. The error was:

Cannot run program "chmod": java.io.IOException: error=24, Too many open files

While, “too many open files” usually means one can raise the limit of open files under Linux (check out ulimit -a) it unfortunately did not help in this situation. I even rebooted the whole server and made sure that no other service was running, except Java that is. Still no success.

I then looked at my code in the CFML (Coldfusion) template. In order to create the directories I used a simply:

&lt; cfinclude action="create" directory="..." mode="775" &gt;

Normal code, right? Well, as it turns out, I simply had to remove the “mode” part in order to overcome this error. Not sure, why this caused a “too many open files” error, but it worked in my situation. I can only imagine that the server tried to put all 2000 directories into memory and then write them in one go (I have a high value for the open files limit set and 12GB RAM).

In any case, hope this helps someone out here.

How to wait until a file is downloaded or why cfthread is a bad idea within a cfloop

I just run into an issue where one of our servers was totally bogged down when users started to download 100 or more files. See, the problem is that we had to check that each file was downloaded successfully before processing with the rest of the code. In other words;

1) Query for files that need to be downloaded
2) Loop over the records
3) Within loop download the file
4) check if file has been downloaded successfully
5) continue with the code.

In Coldfusion (or CFML to be general) your code would look like:

<cfloop query…>
<cfthread…>
<cfhttp…>
<cfthread action=”join”…>

As I mentioned above, we need to check if the file has been downloaded successfully before continuing with the next download. That’s why  there is a cfthread in this code.  Now, while this might be a good idea with small download, it has a hazardous effect if you will trigger 1000 downloads, which again would create 1000 threads!!!

So, there are actually 2 things I’ve learned from this:

  1. There is no need for the cfthread. Since cfhttp will halt the code process until the file has been downloaded, creating the thread is not needed.
  2. Creating a thread within the iteration of your resultset (cfloop) is a VERY  bad idea!

Installing memcached on Ubuntu for wordpress and phpbb

As an application maintainer you always look for the best performance in your application and website. At one point in your quest for the best performance you will undoubtedly trip over memcached.

In short memcached is (quote); Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

That said, installing is a no brainer as well. On Ubuntu you simply need to do the following:

apt-get install memcache
apt-get install php5-memcached

That’s it. Your system takes care of the rest and you will have your first memcached server up and running. Of course, the final step will be to restart apache in order for php to pick up the changes.

Now, memcached alone is of no good use, if your code/application can’t work with it. Thus here I’ll outline 2 examples.

WordPress: Memcached with the W3C total cache plugin

First off, if you aren’t using the awesome W3C Total Cache plugin you should now run install the plugin immediately (just search for w3 cache in the plugin section of the wordpress administration). Even if you are not using memcached it will boost the performance of your WordPress site manifold.

Now, to enable memcached for your WordPress site is as simple as selecting the memcached option for the cache. with the plugin you can even select what you want to place into the memcached cache. Quit slick.

 

Configuring phpBB to use memcached

Actually it took some time to figure this out, since the setting were not so apparent, so I’m hopping this helps others also. phpBB by default used the local disk for caching. This can be chanced in the config.php file in phpBB folder. Open it and ADD or change the following lines:

$acm_type = 'memcache';
@define('PHPBB_ACM_MEMCACHE_HOST', 'localhost'); // Memcache server hostname
@define('PHPBB_ACM_MEMCACHE_PORT', 11211); // Memcache server port
@define('PHPBB_ACM_MEMCACHE_COMPRESS', false); // Compress stored data
$load_extensions = 'memcache';

Especially the last line with “load_extensions” is important. Save the file and restart apache. Now phpBB will use the memcached server(s). Alone on a board with 800 users I have seen a massive speed improvement.

That’s it. Next up is to get all my CFML apps to work with memcached :-)

Coldfusion: How to pass struct and array in a URL

A user just asked:

I need to pass my array to a webserver. But somehow, the array passed with cfhttp throws an error. Please help

You can not pass a structure or an array in a URL as they are complex values and Coldfusion does not have a way to convert them to simple string values (this is what you need to pass in a URL).

The only way to pass complex values is to serialize the Coldfusion struct or array for the URL. Fortunately, Coldfusion has a built in function called “SerializeJSON” to create a simple string. On the other hand, you can convert the simple string back to a struct or array with “DeserializeJSON”.

Here is a simple example how to pass a 2 dimensional array with cfhttp:

<cfset myar = arraynew(2)>
<cfset myar[1][1] = "keywords">
<cfset myar[1][2] = "Razuna, Wordpress, Tomcat">
<cfset myar[2][1] = "description">
<cfset myar[2][2] = "Razuna is a dam with a lot of features">

<cfset thejson = SerializeJSON(myar)>

<cfhttp url="function.cfc">
      <cfhttpparam name="jsondata" type="URL" value="#thejson#">
</cfhttp>

FFmpeg — here we go again

My two other posts on FFmpeg entitled “Installing ffmpeg on CentOS 5” and “SELinux with ffmpeg” already explained in deep how to get FFmpeg up and running.

Unfortunately, today one of our servers just reported a plain:

ffmpeg: error while loading shared libraries: libfaad.so.0: cannot open shared object file: No such file or directory

when trying to run any ffmpeg command. Now, what was that and foremost why? Especially, since it worked 2 days ago. I guess, “someone” must have done some update. In any case, it was a good lesson to reinstall ffmpeg and bring all libraries up to date.

So, since my last installation, some things must have obviously been changed behind the scenes, because when I tried to configure ffmpeg with the same commands I run into another error which was:

libx264 version must be &gt;= 0.78

Even thought I installed x264 from the latest GIT repository it still showed me the above error! Looking around the Videolan.org website I saw that the nightly snapshots differ in size a lot. So, either their nightly script is broken or something else is going on. In any case, I went with the x264-snapshot-20091031-2245 one.

Configured and installed it. Then did a “ldconfig -v” (in order to see that it really took the latest one) and went on with the ffmpeg configuration (I took the latest code from SVN (Revision 20525)) and low and behold, everything compiled and installed without problem.

Important: Update your libraries after the installation of ffmpeg again with “ldconfig”! Else you will get the “ffmpeg: error while loading shared libraries: ….” error again.

Tomcat and directories

I run into a nasty issue the other day with “alike” directories in my web application.

That is, I had a copy of a “WEB-INF” directory called “WEB-INF–”. While my web application did not bother with copy of the WEB-INF directory, Tomcat threw all kinds of errors in the catalina.out log file. Also, I had some issues with Tomcat restarting and strange Java error messages, like:

Java.lang.NullPointerException
com.nary.util.Localization.convertCharSetToCharEncoding(Unknown Source)
com.naryx.tagfusion.cfm.engine.cfEngine.getDefaultEncoding(Unknown Source)
com.naryx.tagfusion.cfm.engine.cfFormData.<init>(Unknown Source)
com.naryx.tagfusion.cfm.engine.cfFormData.<init>(Unknown Source)
com.naryx.tagfusion.cfm.engine.variableStore.<init>(Unknown Source)
com.naryx.tagfusion.cfm.engine.cfSession.<init>(Unknown Source)
com.naryx.tagfusion.cfm.engine.cfEngine.service(Unknown Source)
com.naryx.tagfusion.cfm.cfServlet.service(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

After browsing the log files, I saw that Tomcat tried to read the directory and threw a bunch of critical errors while reading those copied directories. I guess, Tomcat got totally confused and tried to overload libraries.

Lesson learned; Never have any copy of the WEB-INF folder within the web application again.

Setting the correct Java version under MacOS X

My favorite scripting language is CFML, or as some know it as ColdFusion. I like it because it is very very powerful, easy to use and can do just about everything your xyz language can do.

For many years, ColdFusion was a closed sourced system, where the former Macromedia and now Adobe got the copyright of the code. Luckily, this has changed when OpenBlueDragon (OpenBD) came to play with the first open source CFML application server. So, now the CFML world got a very nice open source CFML language and server. Our very own open source Digital Asset Management – Razuna – runs on OpenBD as well and comes bundled with it.

Anyhow, the reason of this blog post is not CFML, but how to set the correct Java JRE environment under MacOS X. Then why did I mention CFML and OpenBD in the first place, you might ask?

Well, today I downloaded the latest version of OpenBD which runs now on Java 1.6 and is 64 bit. But when I tried to start our server (Tomcat) with the new OpenBD jar I got the following error messages in the log.

at org.apache.catalina.startup.
Bootstrap.main(Bootstrap.java:413) Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.naryx.tagfusion.cfm.application.cfHttpSessionListener)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal (WebappClassLoader.java:1854)

As we can see from the “Bad version number…” in the above line there must be some misconfiguration of the Java runtime going on. But wait, does my execution of “java -version” not state that I’m running the latest Java version? Reading from those lines, you could think so.

java version “1.6.0_13″
Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)

Apparently when one looks into the Java paths of MacOS X we see that the current “JDK” is set to 1.5 and not 1.6. Judging from this, I tend to think that Apple is not setting the JDK right for Java applications. You might say, well then just set it in the “Java Preferences”, right? Wrong, I already did that as the screen below shows).

Java Preferences

So, in order to solve this, I set the correct JRE_HOME variable in my .profile in order for all Java applications to pick up the current JRE. To do that, you simple edit your .profile (with vi ~/.profile) and add the following lines to it:

JRE_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
export JRE_HOME

Save it, open a new terminal window (or close and open one) and start Tomcat. Now Tomcat is picking up the new JRE path and Java application, in my case OpenBD, that depend on the Java 1.6 JRE version will run.

Configure web server to handle .air files

Recently over at the website of our open source Digital Asset Management company Razuna Ltd., we published a desktop application that was build with Adobe AIR.

Now, while we could easily link to the AIR application, which all end with an extension of “.air”, within the web page it would prompt the user to install the application only under FireFox (both Windows and MacOS X), but users with Safari or Internet Explorer where prompted to download a “.zip” file.

In order to fix this, we had to change the mime type configuration of the web server itself. Now, we figured that there are different solution to this, depending on your web server;

For Apache

Adding the mime type for .air extensions with Apache requires you edit the file “/etc/mime.types” (on RedHat/CentOS) and adding the line:

application/vnd.adobe.air-application-installer-package+zip     .air

Make sure to reboot Apache to apply the changes.

For Tomcat

Adding mime types for your Tomcat installation requires you to edit the file “tomcat/conf/web.xml” and adding a new “mime-mapping” like;

<mime-mapping>
<extension>air</extension>
<mime-type>application/vnd.adobe.air-application-installer-package+zip</mime-type>
</mime-mapping>

Make sure to restart Tomcat to apply the change.

Using .htaccess

If you can’t access the server config files or you simply don’t want to, then the other option is to simply add the mime type to your .htaccess file.  Add the following line to it;

AddType application/vnd.adobe.air-application-installer-package+zip .air

Save it and you should be all set to make it possible to launch the Adobe AIR installer ones your .air file is downloaded.

OpenBD, Open Source CFML server, gets some praise from the community

Among other things, I am one of the members of the OpenBD Steering Committee. OpenBD is the first Open Source ColdFusion Application Server and has a long history of the product itself and the members of it.

But somehow, when the company behind the commercial BlueDragon product decided to open source their J2EE BlueDragon product, something strange happened. Instead of cheering to have (finally) a open source CFML server, the CFML community seamed to dislike it. The reason for this, lies beyond me and does not make any sense. Fortunately, people change!

Today Joe Rinehart, a prominent figure in the CFML community, posted some very nice comments on his blog about OpenBD. The blog title is OpenBD: I’m sorry, it’s actually nice!. Here is a quote from it:

…OpenBD started up, and immediately told me that there was an exception that was entirely my fault.  And the exception information…wow.  Anything and everything:  lines of code causing the problems, the files they were in, all of the scope variables, introspection of the CFCs that were involved, and it was all logged out to an HTML file.  Good job, OpenBD team!  This kind of raising the bar in respect to competitive products is what it’s all about!…

I want to thank Joe for giving the OpenBD product another chance and leaving all the bad vibes behind it. If you too, want to move to a pure open source stack then give OpenBD a chance today.

In case you don’t know, but Razuna, our open source Digital Asset Management, is also based on OpenBD. You can download the complete Open Source DAM offering over at the Razuna website.