Memcache, Increases the Speed of PHP

June 26th, 2007 by Sajith M.R

php-speed.jpg

Hello Friends,

Memory management is the main problem when you extent your website over a wide range. In php there are a lot of method for speeding up the execution. For a simple case. If you write an algorithm for search a particular keyword from a table, you need to go through all the records for total search results. In this case , you probably use array for saving the result. For a single search it is enough. Think, if your site is viewed by more than 100 users simultaneously, a lot of memory will be loosed for saving the search results as arrays, and you need to execute the database query again and again.

If you can save the intermediate array after the queriying and execution for a particular period of time, you can reuse this array for further queries for a particular period. The php function memcache is using for this purpose. For this you need to install memcahced server on your machine.

Sample php code:

//$a = array(1,2,3,4,5);
$mmc = new Memcache;
$mmc->connect(’127.0.0.1′ ,11211 ) or die (”Could not Connect”);

echo $mmc->getVersion();
$mmc->set(’myarray’,$a, false, 60); // the value will be saved with key myarray for 60 seconds

print_r ( $mmc->get(’myarray’) ) ;

//—Code Ends———————————————

For install memcache using cake use this link:

http://jirikupiainen.com/2007/04/11/memcache-cakephp-cache-memcached-component-helper/

For windows use this link:

http://jehiah.cz/projects/memcached-win32/

For more details use:

http://www.danga.com/memcached/.

Another installation method:

http://pecl.php.net/package/memcache

For user manual

http://www.php.net/memcache

Amazon s3 example

June 26th, 2007 by Sajith M.R

s3.gif

Here i give you a sample code , in php, for amazon s3 file upload. Read the code carefully and try to implement.
Best wishes.

// grab this with “pear install Crypt_HMAC”
require_once ‘HMAC.php’;

// grab this with “pear install –onlyreqdeps HTTP_Request”
require_once ‘Request.php’;
// Note that version HTTP_Request 1.3.0 has a BUG in it! Change line
// 765 from:
// (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_postData) && empty($this->_postFiles))) {
// to:
// (HTTP_REQUEST_METHOD_POST == $this->_method && empty($this->_postData) && empty($this->_postFiles))) {
// Without this change PUTs with non-empty content-type will fail!

//Click Read more to continue

Read More »

Amazon S3

June 23rd, 2007 by Sajith M.R

Amazon s3

Amazon s3 is a remote file storing system. It is totally different from Normal Servers like Apache, FTP server etc. If your site burns more bandwidth due to multimedia contents such a video, image, audio etc, the maintenance cost will be very high. For a limited number of page views, local file saving mechanism is ok. Because the cost of bandwidth is comparatively low. But when the data transfer rate become higher, the bandwidth cost should be considered.

In such a case instead of saving files or images in local servers, You can use Amazon s3 server (S3 stands for Simple Storage Service). For this you have do two things

1) Register on http://www.amazon.com/gp/browse.html?node=16427261

2) Use api for uploading your files into s3

The file uploading, deleting etc functions are not like normal FTP. S3 uses different services for this purpose. Service means Webservices. Apis are available for ASP,ASP.net PHP, C#, Ruby , JAVA, PERL etc

Developers, please use this link for details:http://docs.amazonwebservices.com/AmazonS3/2006-03-01/gsg/?ref=get-started

Putty

June 17th, 2007 by Sajith M.R

putty.gif

Putty is a n implementation of ssh / telnet for win32 and unix application. If you are using windows desktop and your website is hosted in a linux machine, putty helps to ssh from your windows to a linux machine.

You need to do two things for this.

  1. Download putty.exe from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  2. Enter your host address and your access information (user account)Now you can execute linux commands from your windows machine.
    This is just an information about putty.

Do OS programming…Get the essence of programming

June 15th, 2007 by Sajith M.R

osprogramming.jpg

Operating system level programming has a different taste than any other
programming. It is very simple to understand the operating systems layers if
you do os programming in linux. You can start that with system calls such as
fork, pipe, memget, kill etc .

For example, you know pipe. In linux command prompt ‘|’
is using for pipe. For example ls is the command for list the directory …
ls | more means ?? It means give the output of ls command to more command. “more”
command’s input will be the output of “ls” command. Here the
output and input are piped. Standard input and output are changed.
(“more” command is using for showing page by page data)

Example Code:

Click read more for sample code

Read More »

Firebug, Mozilla’s Plugin

June 14th, 2007 by Sajith M.R

firefox.png

The main problem for a web developer is client side scripting and validation. Since the browser never hang at javascript errors, sometimes we cannot find out where the error actually happened. A lot of scriptings may change the innerHTML value of document. Browser’s View source only allow as to see the downloaded page’s html codes, never gives the status of current html .

Firebug is a plugin for mozilla, which help us to debug javascript. The javascript debugging is only one of its features. We can edit html code dynamically, can edit style sheet, and can even edit javascripts variable values, add watch for variables etc like a normal programming IDE.

Here is the link: https://addons.mozilla.org/en-US/firefox/addon/1843

I know, it will be very useful for you. If so comment me back

Regards
Sajith

Ajax, Everybody knows, But …

June 14th, 2007 by Sajith M.R

Ajax Every Body Know

A website without ajax is very rare now a days. Gmail gave us the exact feeling of online by lively giving information of mails, chats etc. Ajax is exploring world wide web through n! (n factorial) Dimentions. Many pages websites are minimized into a single page website and rest part gives to ajax to load. Browsers back button has less meaning while using fully ajaxed websites.

For example: http://www.campaignmanager.in

Search Engine optimization also facing another problem due to this ajax. The spider crawling among websites link points are “html links”. They crawl from one page to other through links. But in the case of ajax, if the next pages are the result of an ajax call, the spider cant proceed further crawling… For that purpose, the developer should concentrate on search engine crawling while the creation of fully ajaxed sites (if needed).

AJAX stands for Asynchronous JavaScript and XML. Asynchronous means without affecting normal operations of browser, an asynchronous web request call is made to get further data. The data transfer takes place in XML format. Javascript is the programming language using for calling this. Thus , AJAX.

Read More »

Agile Software Development

June 13th, 2007 by Sajith M.R

agile-chart.gif

We heard about a lot of software life cycles such as water fall model, spiral model etc. These all are for simplifying the steps in a software development process going through , requirement analysic, design, coding , testing, delivary , maintance etc. But the thing is different in the case of fast and repid application development.
When the requirement of client changes week by week or day by day, The development by taking all the requirement (fixing) is not that much simple. In that case another model of development process is needed . Agile software Development sometimes do this.

Agile software development is agile in two main ways: the infrastructure for software development is agile (the poeple, processes and technologies); and the software itself is agile, enabling the accommodaton of changing client requirements till the very end.

Development of software happens in small chunks- one or a few functioanlities at a time. Ecah of these chunks is a project in itself, and goes through all stages lime design, development, testing, etc. This chunk can even be delivered completely to client, so the client is also happy !

Once a chunk is over, then work on another chunk begins- and its like starting on a clean slate; work is not affected if requirements or even the process itself changes in the meanwhile ! So, its completely ‘agile’. An important aspect of agile development is the feedback.

ThoughWorks Studios has developed Mingle- a software project management platform that supports agile software development.

http://studios.thoughtworks.com

courtesy: IT

Web 3.0

June 13th, 2007 by Sajith M.R

web30.jpg

What is happening in web applications or website. W3C defines a lots of web versions month by month. We just heard about Web2.0. What is the difference between normal web and web2.0 . I have a lots of doubt here. My knowledge is web2.0 provides more interations to client than a normal website, the tagging , blogging , community sites are example for web2.0 (This is only my knowledge).

But now its shifted into Web 3.0.

Web 3.0, popularly known as Semantic Web, is going to enable computer programs to interact with people and websites. Its unfair to call Web 3.0 just another version of current web, as it going to be a huge qualitative leap from the current form. Others refuse to call it version 3.0 because the term, ‘ Semantic Web’ was coined by Tim Berners-Lee when he started work on the concept even before Web 2.0 was born.

Lets expect a leap or crawl deviation for the current web version. Wait and See..

Yours

Syth

ffmpeg sample code

June 12th, 2007 by Sajith M.R

ffmpeg.jpg

Install ffmpeg library in your server first.

Place a video file of any type on current directory (or anywhere), here it is clock.avi .

Click more for source code:

extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

$ffmpegInstance = new ffmpeg_movie('clock.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();

//___________________________________Code end here_____________________________________

I also can be used for file format conversion

Eg: exec(’ffmpeg -i ‘.$SourcePath.’ ‘.$Destination);

Here $SourcePath any file of any format , and destionation also another format.

eg: exec(’ffmpeg -i saji.3gp saji.flv’);

Email Reading Library (Source Code)

June 12th, 2007 by Sajith M.R

php email library

With the support of component ezc , You can read your email via pop3 protocol.

The email and password used here are only for temporary purpose. Try this code:

Click more for source code:

Read More »

PHP zipping algorithm

June 12th, 2007 by Sajith M.R

php zipping library

How can we zip two files and save output as output.zip. For example, in gmail you can download all the attachment as a single zip file. How can we write that code using php.

Click more for Source Code:

Read More »