Wednesday, August 14, 2013

How to speed up your php website

There is a nice technique to reduce the amount of calls your browsers has to make to the server. This will be every image, every css and every JavaScript file included in the webpage. Each time you want to load in one of these elements you will be sending a request to the server which will return the requested object known as a HTTP request.

Reduce Page Loading Time With PHP

Each one of these uses up time on your page loading, so to reduce page load all you have to do is reduce the amount of calls being made. But what if you want to organise you JavaScript files, jquery file, general file, application file and page file. There could be upto 4 requests for some javascript for the page.

It is possible in PHP to combine these JavaScript files together and trick the browser into thinking they are just one JavaScript file, therefore reducing the amount of calls being made to the server. This is done by reading the JavaScript with PHP then changing the header to JavaScript like the example below.

Create a PHP file and use the readfile function to bring in your Javascript files then change the header to Javascript and the server will treat this page as Javascript.

readfile(jquery.js’);
readfile(general.js’);
readfile(jquery-ui.js’);
readfile(page.js’);
header(‘Content-type: text/javascript’);



This technique can be used for css files too.. cheers and thanks to paulund.

ffmpeg mp3 file crop and reduce bit rate

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec - the leading audio/video codec library.

Now i am used this ffmpeg tool to crop the mp3 song for particular minutes and change the quality of the song.

CROP:

  • ffmpeg -t and -ss (output-only) options are now sample-accurate when trans-coding audio
  • 1 is the starting point of the mp3 and 120 is the number of seconds   crop the song.
  • input.mp3 is your input file name and output.mp3 is the result store that name  in the same path.

Example:  exec("ffmpeg -ss 1 -t 120 -acodec copy -i input.mp3 output.mp3");

Change the bit rate:

  • Convert mp3 to lower bitrate using ffmpeg
  • 96k is the bit rate. if you want like 126k ,320k just need to adjust that.

Example: exec("ffmpeg -i input.mp3 -ar 44100 -ab 96k -f mp3 output.mp3");