Archive | open source 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 search & replace in MySQL

Thinking of a way to quickly search & replace data in a MySQL column got me to this solution:

update table
set 
column = replace(column,'thistext','thattext')

With this method I was quickly able to change millions of records today. Quick and easy.

Ubuntu 10.04 LTS server always selecting older kernel despite updates

I hit a really strange issue for some time now with one of my Ubuntu 10.04 LTS servers where, despite doing recent kernel updates (the latest is 2.6.32-33) it always booted into the kernel 2.6.32-28. No matter what I did (update-grub, etc.), the server was sticked to 2.6.32-28.

After searching and reading a lot of posts and wiki pages I still couldn’t find a solution for it (most blogs and wiki pages talk about compiling a new kernel or installing a new one, but none talked about selecting the proper kernel or fixing it manually).

But since I had some other server, that booted into the correct kernel issue, I luckily had some config files to compare. The one that I was after is the “menu.lst” which is a GRUB file and is located at “/boot/grub”. Looking at the menu.lst from the working server and comparing it to the “not working” one, revealed that the “non working” one had UUID’s declared for each server while the working one not UUID but “root (hd0,0)” and hard coded root paths of “/dev/sda3″.

Working config:

title   Ubuntu 10.04.2 LTS, kernel 2.6.32-33-server
root    (hd0,0)
kernel  /vmlinuz-2.6.32-33-server root=/dev/sda3 ro quiet splash
initrd  /initrd.img-2.6.32-33-server
quiet

Not-Working config:

title   Ubuntu 10.04.2 LTS, kernel 2.6.32-33-server
uuid  9823d540-6bf0-467a-8640-39d33c7544fb
kernel  /vmlinuz-2.6.32-33-server root=UUID=d9e79ad9-6d53-4cb5-85d6-e9f1eea712f2 ro quiet splash 
initrd  /initrd.img-2.6.32-33-server
quiet

As you can see from the this, the UUID and the root are quite different. I can’t actually explain why this configuration took place on this particular server. This is even more surprising since both servers are being “kept in sync” (with updates and such).

In any case, the resolution (for me at least) was to copy certain parameters over to the “not-working” menu.lst. Those were, the root path (/devsda3), the “root (hd0,0)”, the “groot=(hd0,0)” plus the “kopt=root=/dev/sda3 ro” lines.

It took a long time to fix this issue and and I hope this helps someone else.

svn: warning: cannot set LC_CTYPE locale

Somehow with the recent Ubuntu 10.04 LTS updates or maybe with a subversion update, I received some errors message of the type “locale…”. To be more precise the errors are;

svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LC_CTYPE is UTF-8
svn: warning: please check that your locale name is correct

While all SVN commands still worked, it was something I didn’t tackle with immediately. But today, I set out to fix it. Well, it only took a minute or so :)

So, if you want to fix this all you have to do is to set the “LC_ALL” variable manually. To make it permanent just edit the file “/etc/environment” and add the line:

LC_ALL=C

Save the file and exit the editor. In order for it to apply you have to logout of the current shell session. The next time you log in, the issue with SVN will be gone.

 

Seamless server access from MacOS X to Ubuntu with SSH public keys

When you access a server over SSH you usually get asked for a password that you trustfully type into the terminal window. But doing so is insecure for many different reasons (I’m sure there are many people who wrote about this before and describe it better then I ever could). So, what is a better way to log into your server then? The best way so far is a method called “public key authentication”.

So, since we want to add security to our belt, we can simply use this technique for our SSH access as well. On MacOS X it is actually very easy to setup.

First up, you need to create your own keys. Doing so, is straight forward, all you have to do is to open up a Terminal window and type “ssh-keygen”. This will then prompt you some questions, where to put the keys (use default) and for the passphrase (I would suggest you use a good password). In the end, it will save your keys (your private one and a public one) to your .ssh directory.

Now what you got your public key, all there is left to do is to copy your public key to your server. In case you have root access to your server, it is simply a manner of doing it with “scp”, like:

“scp ~/.ssh/id_rsa.pub root@{yourserverdomain}:.ssh/authorized_keys”

This will copy your public key to the “authorized_keys” of the server.

Once done, you can now simply log into your server with ssh root@{yourserverdomain} without the need to enter a password since your server and you exchange keys for authentication.

Troubleshooting

When you copy your key to server you might get a error that the file “authorized_keys” is not found. If so, then simply create the file on the server and issue the copy command again.

 

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

Celebrating 20 years of Linux

I remember when I installed Linux the first time (many many moons ago) and it was all cryptic for me. All that starred at me, was a black screen with some strange symbols and a pointer blinking.

So, this is Linux, I thought and tried to get my way around it. To be honest, it took a couple of re-installs and some learnings to come to the level I’m at now. Nowadays, all of my applications run on Linux servers (my favorite one is Ubuntu server) and I have to say that I’m more then happy how Linux performs.

Actually, my next step is to adopt Linux (Ubuntu) on my laptop, but to move to Linux on my desktop, I really need to have a application like Aperture of Adobe Lightroom. Apart from that, I think Linux on the desktop has a big chance to succeed. Especially, Ubuntu 11 with Unity will probably make this move apparent for a lot of users.

In any case, if you run Linux on your servers or thinking of migrating to Linux, you own it to yourself to watch the below anniversary video and head over to the dedicated “20 years of Linux” site.

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>

Changing the default search engine in Firefox

On a Windows machine I came upon the other day (forcefully and not intentional:-) ) I saw that the default engine was “search-results.com”. This URL was called whenever the user entered a keyword in the URL bar (you do know that Google Chrome and Firefox 4 will automatically search for the words you enter in the URL field, don’t you?). Key was, that I wanted to change this URL.

Easy right? Well, as it turned out, it took some small effort to find the right value.

First off, I entered the “about:config” and searched for “browser.search.defaultenginename”. Double clicked on it and changed it to “Google”. Immediately, I restarted Firefox, but unfortunately the search still was being directed to the other site.

Ok, hitting again the “about:config” and this time searching for “search” only revealed that there was another setting called “browser.search.defaultengine” which also pointed to another search engine. Changing it to “Google” also did not help.

Finally, after looking for some more, I find out that the config value “keyword.url” is the one setting that needs to be changed. Low and behold, Firefox even has a nice page on this topic (you just need to know what you need to be looking for, right…).

In short changing the value back to the default value (or any other you want) “http://www.google.com/search?ie=UTF-8&oe=utf-8&q=” fixed it.

Hope this helps.