Ajax taking too long to come back


Ajax taking too long to come back



I am recording 2-4 seconds of audio on my website and using Ajax I am posting it to the server. Some time this Ajax take 4-5 seconds, on the other hand some time it takes up to 2 minutes for uploading the same file. The file size is around 360kB. I want the Ajax to drop the file on the server and come back instantly and let the server keep processing it and meanwhile the user can start recording the next file.



I am using webRTC to record audios and working on Yii 1.x


//create FormData
var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);

callback('Uploading ' + formData + ' recording to server.');
//ajax call
makeXMLHttpRequest('captureFile', formData, function(progress) {
if (progress !== 'upload-ended') {
callback(progress);
return ;
}

var initialURL = '<path to upload a file>';
callback('ended', initialURL + fileName);
});

function makeXMLHttpRequest(url, data, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
callback('upload-ended');
}
};

request.open('POST', url);
request.send(data);
};



on success next ajax perform its operation for initiating recording of the next file.



How can I make sure that this ajax only drop the file to the server and return back and server process the file and not stall ajax to finish file processing.





360kB ... which possibly gets encoded in such a way that the sent data is 4/3 times that, which is 480kB ... or 3,840mbits ... on a one megabit upstream connection, that would take over 4 seconds (including overhead) ... so, what is the speed of your internet upstream? This is the deciding factor to how long this takes
– Jaromanda X
Jun 30 at 6:22


360kB





I want Yii to auto trigger audio processing and return the Ajax back to the front end so that user don't have to wait for audio processing to finish. When audio is processed, then maybe we can send an updated about it on the front end.
– Curious Developer
Jun 30 at 6:55






yeah ... but what's the upstream speed?
– Jaromanda X
Jun 30 at 7:10





how can i find that?
– Curious Developer
Jun 30 at 7:17





no idea ... speedtest.net - of course, if this code is being used by others, then your upstream speed is irrelevant - it's the end users upstream speed that is impotent
– Jaromanda X
Jun 30 at 7:18









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV