Much of web applications use modal dialog or pop up message on several page. So de idea is to make creating modal container at once and use it anywhere. It’s easy as just pass the content to the plugins.

I use libraries that commonly used over the world.Those are Jquery, Twitter bootstrap, and bootstrap Modal. And I will write my plugins on generic-modal-container.js file. Look at code below for the complete plugins.

Sometime we write AJAX based application which has many ajax call. If an AJAX called, we add loading image indicator to show that request being processed. For simply way we use AJAX beforeSend() and complete() events for show and hide loading image indicator. See code below:

When we write much of AJAX call, we waste our time to write beforeSend() and complete() events for each AJAX calls. It’s also affect on total lines of code.

The better solution, we can use AJAX global events which always called when an AJAX request fired. Let’s try to modify code above:

// This event is triggered if an Ajax request is started
// and no other Ajax requests are currently running.
$(document).ajaxStart(function() {
$(this).showLoading();
});
// This global event is triggered if there are no more
// Ajax requests being processed.
$(document).ajaxStop(function() {
$(this).hideLoading();
});
// call an AJAX request
$.ajax({
url: 'sample/url/target.php',
success: function(result) {
// do when success AJAX called successfully
}
});
// call an another AJAX request
$.ajax({
url: 'sample/url/another_target.php',
success: function(result) {
// do when success AJAX called successfully
}
});

That’s, we just define global AJAX events once, and call many AJAX request. We can also disable global event for a particular AJAX request by passing global option to false on an AJAX request like below:

Problem

This morning I got problem that performance of my application going slowly. This case just occur at this moment, not before. The application just worked yesterday and the days before.

Well, It’s just on development phase and it scared me. If the application has worst performance on development, how can I step forward to production?

Getting a Solution

Firstly, I check the error message. PHP and Apache log file to ensure there is a code failures that guide me to fix this problem. All show no error reported except just “Application timeout”. When I have no clue what pieces of code going wrong and work unexpected, I have an idea: “It’s time to profiling my code. Maybe there is unstopped loops that I don’t know where it is.”

And now, I run my application. Once application started, Xdebug will provide files that show us the application performance. This is just text file so we can read it directly using text editor like notepad. However, I confuse to read the information, so I decide to read using Qcachegrind.

Just run qcachegrind.exe and select xdebug profiler output file as look like image below.

And… gotcha…

Look! QCachegrind show me that CI_log->write_log() method take most of all time.