I'm writting an application by PHP, an online air ticket booking. Problem is the speed so low. I must send a request to airlines sequentially.
I'm using Ajax to airlines 1, get response then finish show result to user, then request to airlines 2, get response then show result....
Do this with three airlines, it take 30 second. I wonder if I have 10 airlines, it's horrible.
So I wanna know how to solve this problem.
I search for Ptheads but maybe it not a good solution.
Thank for man with experience with this.
Here is my code:
In javascript
$(document).ready(function () {
var base = $('base').attr('href');
//When finished loading ticket search result page
//I call three ajax to my php script, this script send request to airlines
//And return result here.
//First airlines call
$.ajax({
url: base + 'flight/jetstar',
success: function (data) {
data = $.parseJSON(data);
//This will show result to user (function had defined before)
$.each(data, function (key, item) {
all_flight[key] = item;
item.sort(compare);
listFlights(item, key);
});
}
});
//And next airlines
$.ajax({
url: base + 'flight/vietjet',
success: function (data) {
data = $.parseJSON(data);
$.each(data, function (key, item) {
all_flight[key] = $.merge(all_flight[key], item);
});
$('.departure_list').html('');
$.each(all_flight, function (key, flight) {
flight.sort(compare);
listFlights(flight, key);
});
}
});
//And Final
$.ajax({
url: base + 'flight/vna',
success: function (data) {
if (data != '0') {
data = $.parseJSON(data);
$.each(data, function (key, item) {
all_flight[key] = $.merge(all_flight[key], item);
});
$('.departure_list').html('');
$.each(all_flight, function (key, flight) {
flight.sort(compare);
listFlights(flight, key);
});
} else {
var p = '<p class="text-center">No ticket found</p>';
var dbody = $('.departure_list tbody tr');
if (dbody.length == 0) {
$(p).insertBefore('.departure_list');
}
}
}
});
});
PHP just use cURL for rest api