Search code examples
phpmysqlajaxclient-side-scriptingserver-side-scripting

Call a heavy PHP function through a loop AJAX or server-side


Which one is best when to choose from server-side or client-side? I have a PHP function something like:

function insert(argument)
{
   //do some heavy MySQL work such as sp_call
   // that takes near about 1.5 seconds  

}

I have to call this function about 500 times.

for(i=1;i<=500;i++)
{
  insert(argument);
}

I have two options:

a) call through loop in PHP(server-side)-->server may timed out 
b) call through loop in JavaScript(AJAX)-->takes a long time.

Please suggest the the best one, if there is any third one.


Solution

  • So Finally I Got this.

    a) Use AJAX if you wanna sure that it will complete. it is also user-friendly as he gets regular responses between AJAX calls.

    b) Use Server Side Script if you almost sure that server will not get it down in between and want less load on client.

    Now i am using Server Side Script with a waiting message window for the user and user waits for successful submission message else he have to try again. with a probability that it will succeed in first attempt is 90-95%.