![]() |
Many many AJAX calls, how to make it work
I have this system that I am making and the final part of it requires that I transfer content from one system to another once a day. We are talking about somewhere around 50K sql queries (Don't ask, I didn't make it I am just moving it :(). Problem is I cannot do that many in PHP without a timeout issue, not to mention the client will get tired of just sitting there waiting and the apache timeout limit will be met also.
So I figured I'd do it with a progress bar and ajax. I got the system setup right to accept the calls and run through the script just fine, that's not a problem. The problem is the DOM freezes because my ajax calls are not Async. Here is my script: Code:
function ajax ( func, params, coms ) {As you can see I have to run a date loop to run through all days selected. Plus I also have to run through a mysql query loop, hence the returned Z data, there are 625 fields that are returned, for each field returned there are two companies and for all of them there are approx. 5 queries to run. So I have a loop that has to be run through. Any thoughts on how to do this? It works right now, it just doesn't update the DOM since it's frozen on a sync loop. Thanks for the help. |
collect then report:
Code:
function square(n){return n*n;} |
Yeah, but you can only have X amount of max async calls in a browser at one time, I would max way out with the 625 calls that it makes to the script. Plus there's no way to know if their are 625 records or less or more.
|
Quote:
you trigger the next call or batch of calls upon the arrival of a call. i'm not sure what your server spits out, but i faced a related challenge doing a CMS content dump, from a mysql db. i used LIMIT to ask for 100 rows at a time, range specified in the url. if the result set came back with 100 entries, i incremented the range by 100. if it had fewer than 100 rows, that set was complete and i invoked the collector callback to save the collated results to a file. to get started, i would break your code into more re-usable functions. get the logic out of the loop. once you get everything broken up, it will be much easier to start making it async. in particular, Code:
while(num1 <= num4) {Code:
function next(num1, num4) {also, i would look at the sql, you should be able to combine a lot of those queries before they are served. use joins to create a wider table of data to avoid repeated calls. also, this line: Code:
z = j.parseJSON(ajax('countPolCar', s.params.curdate, '')); |
Hmm, ok now that makes more sense. Thanks, let me check into that tomorrow then. Thanks for the help.
|
WOW, worked like a charm! Thanks for the advise, now I just gotta finish all the other queries ha ha ha
|
| All times are GMT +1. The time now is 01:57 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.