Stress testing and profiling tools for web application

Hi there,

Recently I came across some cool new tools along with some of my old favorites and thought this calls for a quick post -

Front End Profiling Tool:

FireBug: Firebug is pretty handy to find out how long it is taking your website to load and render as well as how many header calls are made to fetch external java-script and css files. It also packs lots of useful tools and a must have for any serious web application developer.

YSlow:YSlow sort of gives your an easy to understand report on your web pages flaws and how to overcome them.

Web Server Stress Testing Tool:

Siege: Siege is a command line tool that you can install and simulate concurrent hits to any particular URL.

Example:

siege -c 10 -r 10 http://www.mydomain.com/

Above code pings the URL concurrently with 10 connections repeating 10 times making 100 hits to the URL.

MySQL database Profiling Tool:

Jet Profiler:Jet profiler Shows the real time activity of the connected mysql database once its hooked up. It is pretty useful when used together with the siege tool and see how concurrent hits affect the database.


Naturally these are not all that is out there so any new inputs from the readers will be most welcomed :)





thanks,

faisal ahmed

web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com

Share

Linux: Bash script for dynamic symbolic link creation

Hello everyone,

I just created this simple but useful bash script to create symbolic link. It lets me avoid going into my local server root located at /var/www/ and instead symbolic link of a folder located at /home/public/ is created at /var/www/ so anything that you put inside /home/public/project1 or project2 or whatever the folder name is it also gets reflected and thus can be accessed via link http://localhost/project1 or http://localhost/project2 and so on.

STEP 1: create a file named symlink at /home/public/ or anywhere you like. Then copy the following code inside it and save it.

  1. #! /bin/bash
  2. sudo mkdir -m 777 $1
  3. sudo ln -s /home/default/Public/$1 /var/www
  4. echo $1 symbolic link created


STEP 2: To use the script to create a folder and create a symbolic link at the server root located at /var/www/ you have to type in the following code and press enter.

  1. sh symlink faisal


On the above code sh is the prefix required to run the bash script named symlink and faisal is the name of the folder i want to create and link to /var/www/

Hope the above snippet was useful.



thanks,

faisal ahmed

web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com

Share

google +1 button onClick event

Hello there,

I was recently working with google +1 feature and came about this trick to trace if someone clicked the button or not.

CODE :

  1.  
  2. <html>
  3. <head>
  4.     <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
  5.     <script type="text/javascript">
  6.        function testme(){
  7.           alert(‘test’);
  8.        }
  9.     </script>
  10. </head>
  11. <body>
  12.     <g:plusone callback="testme" href="http://www.faisalbd.com/"></g:plusone>
  13. </body>
  14. </html>
  15.  



Hope it helped someone :)


thanks,

faisal ahmed

web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com

Share

Dummies guide to LAMP setup on linux :)

Hello everyone,


Recently I came across several nifty apt-get commands that quite handy and if used properly can be a life saver while setting up LAMP stack on your system.


Step 1 : One line LAMP setup on linux -

  1. sudo apt-get install lamp-server^



Step 2 : Setup phpMyadmin to manage your mysql databases -

  1. sudo apt-get install phpmyadmin



Step 3 : Setup xdebug and integrate with php5 installation -

  1. sudo apt-get install php5-xdebug



Step 4 : Setup cURL -

  1. sudo apt-get install php5-curl



After the above command finishes installing curl do the following -

  1. cd /etc/php5/conf.d/
  2. sudo gedit xdebug.ini



After opening the file in gedit, add the following lines at the end of the file then save and close it.

  1. xdebug.remote_enable=On
  2. xdebug.remote_host="localhost"
  3. xdebug.remote_port=9000
  4. xdebug.remote_handler="dbgp"



The following step is helpful for those who later want to integrate andorid SDK, because only Sun JDK is supported when running the android SDK app, is handy if you use it.


Step 5 : Setup sun -

  1. sudo apt-get install sun-java6



Step 6 : Enable Rewrite Module for PHP -

  1. a2enmod rewrite





The above will do a smooth install of a functioning LAMP server on the system :D , comments and queries are always welcomed.


thanks,

faisal ahmed

web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com

Share

Codeigniter: Helper for template library dynamic view partial loading

Hello everyone,

I have recently been in quick-fire blogging mode. After playing with the superb template library developed by Phil Sturgeon.

The following template helper is the outcome of tweaking that makes life easier while setting up view partials and calling them inside the layout dynamically. The helper also has an add-on use which gives user the option to use region specific partial loading.

Controller:

welcome.php

$partial_list[]['region'] = 'left';
$partial_list[]['name'] = 'category';
$partial_list[]['view'] = 'partial_category';
$partial_list[]['region'] = 'right';
$partial_list[]['name'] = 'login_box';
$partial_list[]['view'] = 'partial_login';

/* following functionautomatically sets the partials
* based on the above array and also passes $partial_list
* variable to the view.
*/

/*
* make sure the pareser helper is loaded before
* calling this function
*/

setup_partials($partial_list);

$this->template->set_layout('home_layout');
$this->template->build('home_view');


Layout:

home_view.php

<html>
<head>
	<title><?php echo $template['title'];?></title>
</head>
<body>
	<div class="left">
		/* Will show only partials with region set as left */
		<?php show_partials('list', 'left', $partial_list, $template); ?>
	</div>
	<div class="mid"><?php echo $template['body'];?></div>
	<div class="right">
		/* Will show only partials with region set as right */
		<?php show_partials('list', 'right', $partial_list, $template);?>
	</div>
</body>
</html>

Detail about the usage can be found in the actual helper file, also feel free to comment here and I will try my best to help out.

Download Helper:

DOWNLOAD PARSER HELPER

thanks,

faisal ahmed

web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com

Share

Google translate helper for codeigniter

Hello everyone,

I am back with a tiny contribution. Today I have created a nifty helper for codeigniter which uses the google translate api (v2).

In order to use the function you will require a google translation api key which you can get for free the google api console (https://code.google.com/apis/console).

After you have your key it has to be passed to the function along-with the text to be translated, the language from which it is being translated from and to the language it is translated to. The function returns the translated text which can be used to do further processing or can be also be echoed.

CODE:

  1. <?php
  2.  
  3. /* Develeoped by: faisal ahmed <thephpx(at)gmail.com–> */
  4.  
  5.         function google_translate($api_key, $text, $from_lang, $to_lang){
  6.                 $link = ‘https://www.googleapis.com/language/translate/v2?key=’.$api_key.‘&amp;source=’.$from_lang.‘&amp;target=’.$to_lang.‘&amp;q=’.$text;
  7.                 $response = file_get_contents($link);
  8.                 $array = json_decode($response);
  9.                 return $array->data->translations[0]->translatedText;
  10.         }
  11.  
  12. ?>

Hope to be back with another snippet soon, till then keep in touch :)

thanks,

thephpx

Share

Setup xdebug on LAMPP

I am assuming the reader already has LAMPP setup and running on their Linux. First step towards setting up xdebug is to download LAMPP development package add-on from the apache-friends website. After the compressed file is download navigate to the folder where the TAR file is located using linux terminal and the type in -

export PATH=/opt/lampp/bin:$PATH

sudo tar xvfz xampp-linux-devel-1.7.4.tar.gz -C /opt

The above overwrites the existing LAMPP setup and includes the add-ons. After the files are overwritten, type in the following command.

/opt/lampp/bin/pecl update-channels

The above updates the PECL channels and prepares it for PECL based xdebug installation. After the above line is executed type-in:


/opt/lampp/bin/pecl install Xdebug

The above line sets up Xdebug in the existing LAMPP setup and at the 3rd or 4th last line of you will see the location of the xdebug.so files location given, note it down. The location may look something similar to this – “/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so

Now we have to update the php.ini file to include the xdebug settings. You will find the file in “opt/lampp/etc/” open it by typing -

sudo gedit opt/lampp/etc/php.ini

Add the following lines at the very end of the file and save it.


zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so
xdebug.profiler_output_dir = “/tmp/xdebug/”
xdebug.profiler_enable = On
xdebug.remote_enable=On
xdebug.remote_host=”localhost”
xdebug.remote_port=9000
xdebug.remote_handler=”dbgp”

After the file is saved restart LAMPP by typing in -

sudo opt/lampp/lampp restart

To verify goto http://localhost/ after the server is restarted and you will see Xdebug table showing the xdebug settings.

let me know if you come across any issues during the setup process.

~ thephpx

Share

jQuery: input array object validation

Use of input array objects in ajax based forms where we want to give users open ended options to add unlimited number of items and then process them on form submission is very common now a days. As the input elements all have the same name and assuming no class or id attribute is available, validation can be a big pain in the back side.

The following code excerpt shows how to validate in such a scenario -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<meta http-equiv="content-type" content=
"text/html; charset=us-ascii" />
<title>Hello World</title>

<script type="text/javascript" src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
      function checkname(fieldname){
      var field = document.getElementsByName(fieldname+"[]");

      var status = 1;
      for(i=0;i<field.length;i++){
        if(status > 0){
          if(field[i].value == ''){
            status = 0;
          }
        }
      }
      
      if(status == 0){alert('The field can not be empty!');}
    }
//]]>
</script>
</head>
<body>
<form method="post" action="" name="form" id="form">
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <select name="ahmed[]">
  <option value="">None</option>
  <option value="1">1</option>
 </select>
 <input type="submit" value="test" onclick="checkname('ahmed');" />
</form>
</body>
</html>

Comments and queries are welcomed :)

thephpx

[ad code=1 align=center]

Share

Staged Code-Igniter Web Application Development

Today I am going to share a little customization that I do while i develop codeigniter based web application. Now a days in most web application development firms a three-tire development process is followed. This is done to ensure smooth roll-out of the application from development to live.

The three-tire development methodology involves three stages of development servers. First comes the local server which is setup in your laptop or workstation. Then comes the internal test server, which is a central server that holds all the SVN repository as well as hosts the site and make it accessable to all from within the network. This server is also sometimes called staggin server. Last but not the least comes the live server, in most cases its your clients server where you upload your codes after they have passed the QA checks of both local-server and staging-server.

One related aspect of staged development is that in most cases they involve using SVN server for version control. Using SVN, though you can automatically update your server files from SVN server through “svn update” command but if the config file is not configured to take the different servers into consideration you will have to update the config file every time you do update on a server or set separate config file on each server and add the file to ignor list of the SVN repository.

Our way of doing it is to use a single config file and make it lookup the host address to determine which configuration settings to use.  If you are familiar with codeigniter then you already know you will find your config file at system/application/config/config.php.

Find the following line in the config.php file:

  1.  $config[‘base_url’] = "http://localhost/codeigniter/";

Replace the line with the following lines -

  1. if($_SERVER[‘HTTP_HOST’] == "localhost"){
  2.   $config[‘base_url’] = "http://localhost/codeigniter/";
  3. }else if($_SERVER[‘HTTP_HOST’] == "192.168.1.1"){
  4.   $config[‘base_url’] = "http://192.168.1.1/codeigniter/";
  5. }else{
  6.   $config[‘base_url’] = "http://www.live-server.com/codeigniter/";
  7. }

Now all your URL’s will be adjusted based on the server the site is accessed from. Next we will modify the database.php file which is also located in system/application/config/database.php

Find the following line(s) in the database.php file:

  1.  $db[‘default’][‘hostname’] = "localhost";
  2.   $db[‘default’][‘username’] = "root";
  3.   $db[‘default’][‘password’] = "";
  4.   $db[‘default’][‘database’] = "restobolivia";
  5.   $db[‘default’][‘dbdriver’] = "mysql";
  6.   $db[‘default’][‘dbprefix’] = "";
  7.   $db[‘default’][‘pconnect’] = TRUE;
  8.   $db[‘default’][‘db_debug’] = TRUE;
  9.   $db[‘default’][‘cache_on’] = FALSE;
  10.   $db[‘default’][‘cachedir’] = "";
  11.   $db[‘default’][‘char_set’] = "utf8";
  12.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";

Replace the above line with the following once:

  1. if($_SERVER[‘HTTP_HOST’] == "localhost"){
  2.  
  3.   $db[‘default’][‘hostname’] = "localhost";
  4.   $db[‘default’][‘username’] = "root";
  5.   $db[‘default’][‘password’] = "password";
  6.   $db[‘default’][‘database’] = "database_name";
  7.   $db[‘default’][‘dbdriver’] = "mysql";
  8.   $db[‘default’][‘dbprefix’] = "";
  9.   $db[‘default’][‘pconnect’] = TRUE;
  10.   $db[‘default’][‘db_debug’] = TRUE;
  11.   $db[‘default’][‘cache_on’] = FALSE;
  12.   $db[‘default’][‘cachedir’] = "";
  13.   $db[‘default’][‘char_set’] = "utf8";
  14.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  15.  
  16. }else if($_SERVER[‘HTTP_HOST’] == "192.168.1.1"){
  17.  
  18.   $db[‘default’][‘hostname’] = "localhost";
  19.   $db[‘default’][‘username’] = "root";
  20.   $db[‘default’][‘password’] = "password";
  21.   $db[‘default’][‘database’] = "database_name";
  22.   $db[‘default’][‘dbdriver’] = "mysql";
  23.   $db[‘default’][‘dbprefix’] = "";
  24.   $db[‘default’][‘pconnect’] = TRUE;
  25.   $db[‘default’][‘db_debug’] = FALSE;
  26.   $db[‘default’][‘cache_on’] = FALSE;
  27.   $db[‘default’][‘cachedir’] = "";
  28.   $db[‘default’][‘char_set’] = "utf8";
  29.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  30.  
  31. }else{
  32.  
  33.   $db[‘default’][‘hostname’] = "localhost";
  34.   $db[‘default’][‘username’] = "root";
  35.   $db[‘default’][‘password’] = "password";
  36.   $db[‘default’][‘database’] = "database_name";
  37.   $db[‘default’][‘dbdriver’] = "mysql";
  38.   $db[‘default’][‘dbprefix’] = "";
  39.   $db[‘default’][‘pconnect’] = TRUE;
  40.   $db[‘default’][‘db_debug’] = FALSE;
  41.   $db[‘default’][‘cache_on’] = FALSE;
  42.   $db[‘default’][‘cachedir’] = "";
  43.   $db[‘default’][‘char_set’] = "utf8";
  44.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  45.  
  46. }

The above code will give the server specific database configuration to the application based on the server it is accessed from.

Now save these two files and test your application you should be able to use the same config.php file in different servers if they are properly configured on config.php and database.php

For any further query feel free to leave a comment I will try my best to help you out.

take care,

thephpx

Share

Sprintometer as a SCRUM management tool

On my endeavor to find the perfect SCRUM project management tool I came across a freeware option named “Sprintometer”. It is not entirely free as it sounds but the options it gives to a manager for free is quite outstanding. The application can be downloaded from their website { sprintometer.com } for free.

Sprintometer support project mangement in both XP and SCRUM methodology. Once you create a project it first of all asks the way the project is going to be managed. Then onward a product backlog can be prepared with stories and tasks assigned to it. Each task then can be assigned to a developer or a coder or a tester.

On the basis of the project specification the application itself generated some very useful charts that give the manager a good understanding about where the project is actually heading. Some of these charts are -

  • Track Chart: Tracks the amount of work done and the amount of work remaining through a line graph.
  • Scope Chart: Shows in hour(s) the amount of work left against a story.
  • Resource and Budget Chart: A matrix showing the resource and cost both story-wise and day-wise
  • Story Readiness Chart: Shows how much closer to completion a story is through a table.
  • Summary Report: Gives a overall report about the story in terms of work done, remaining and days left.
  • Workload Report: This shows the amount of workload taken on by each project team members.

From a project manger perspective it gives me a complete hold on where my project is heading. But the only thing it lacks is integration of team members to give their inputs directly to the system. Hope they are working on it and will be made available to the freeware version in near future :p

take care,

- thephpx

Share