Schedule tasks on Linux using crontab

by Tweak on April 14, 2011
in Ajax, Linux, Servers

If you’ve got a website that’s heavy on your web server, you might want to run some processes like generating thumbnails or enriching data in the background. This way it can not interfere with the user interface. Linux has a great program for this called cron. It allows tasks to be automatically run in the background at regular intervals. You could also use it to automatically create backups, synchronize files, schedule updates, and much more. Welcome to the wonderful world of crontab.

Crontab

The crontab (cron derives from chronos, Greek for time; tab stands for table) command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. To see what crontabs are currently running on your system, you can open a terminal and run:

sudo crontab -l

To edit the list of cronjobs you can run:

sudo crontab -e

This wil open a the default editor (could be nano or pico, if you want you can change the default editor) to let us manipulate the crontab. If you save and exit the editor, all your cronjobs are saved into crontab. Cronjobs are written in the following format:

* * * * * /bin/execute/schedulescript.sh
Read more…

Install mcache (msession) to be used for session caching in PHP

by Tweak on September 30, 2010
in Ajax

Installing mcache, previously known as msession, on CentOS 32 bit system.

MCache can be used completely transparently to a PHP application. By editing PHP’s “php.ini” file to use MCache as its default session handler (see Appendix D), applications will simply use MCache without knowing. This has an advantage in that MCache presents a standard interface for PHP regardless of it storage configuration. It can even hide which storage system or database is used and provides an amount of connection pooling and SQL caching.

If you are on 64 bit system, you will get errors, lots of them. Following instructions work fine with 32 bit systems. For more help look at the MCache Handbook.

Web site: http://www.mohawksoft.org/?q=node/32
PHP reference: http://us2.php.net/manual/en/ref.msession.php
Read more…

Simple AJAX Example

by Tweak on June 26, 2009
in Ajax

This aims to be the easiest possible example demonstrating AJAX (Asynchronous JavaScript and XML).

AJAX is a technique rather than a technology: It describes how JavaScript can be used to pull data from the server using the XML HTTP Request object and then insert this data into the website using DOM. This is done asynchronously – that is, in the background, without having to refresh the whole page. The technology which AJAX is based on has already been available for a while, the combination is what makes it new.

You can try the examples online or download them and run them locally (except for the PHP script, that would require a webserver with PHP).

1. The DOM

The Document Object Model is the internal representation of your website. The DOM is accessible by JavaScript and provides a way to programmatically insert, remove and modify tags in your website (except that they are called elements or nodes instead of tags, because the DOM manipulates the data model in memory and not the representation as XML). This example shows how to set the content of the element with the id “foo” to “Hello, AJAX world!”: Read more…

AJAXing the Web

by Tweak on June 12, 2009
in Ajax, Javascript

AJAX is one of the hottest new technologies, in the ever growing universe of Web development. In this article, we’ll get to know how AJAX fits in a real-world situation and how you can assess its value in a project. Hopefully, by the time you finish reading this article, you’ll know what AJAX is, why, and how to use it.Nothing really new about what is happening here.

The normal routine in Web development involves requesting a file from the Web Server and receiving a page as response. So whats new with AJAX. Just that the difference, is that requests are being made from the Client side Java Script, which is embedded within HTML.

So what is AJAX ?

AJAX is acronym of Asynchronous Java Script and XML Read more…

JavaScript Browser Detection

by Tweak on June 12, 2009
in Javascript

Browser detection is a vital tool when your web site looks different or does not function correctly when viewed in different browsers. Using Javascript, you can redirect viewers to different pages or display different content depending on a user’s browser.

We will use the index of function and the navigator object in order to preform browser detection. What we first need to do is to determine what type of browser the user is using. To do this, we use the navigator.userAgent function to determine the type (application) being used. We create a variable called browsername to do this. Here is what the script looks like so far: Read more…

Image Rollovers

by Tweak on June 12, 2009
in Javascript

Ever wonder how people make those images switch over when you put your mouse over them? Like so:

Well, they probably used Javascript. This tutorial will demonstrate one of the easiest ways to accomplish the rollover effect. Near the top of your HTML code, you need to insert a preloader script that will tell the browser to download the images you wish to have appear when the mouse is hovering over them. It is usually a good idea to put this code inside the tags. The code should look like this: Read more…

Style Sheet Switching

by Tweak on June 12, 2009
in Html/Css, Javascript

By using a little Javascript, you can allow users to switch between different style sheets and dramatically alter the appearance of a web page’s layout.

This first method creates a persistent style sheet. This means that the style sheet will definitely be loaded and enabled for use on this web page. Most style sheets used on the web are loaded in this manner by placing this code in the head area of an HTML document. The properties of the style change when we add a title attribute, like so:

<link rel="stylesheet" type="text/css" href="preferred.css" title="solder" /> Read more…