Ok, I have been trying to figure out a way to solve my issue, and I am coming up empty handed. I have an AJAX call that is indeed working (I can see the rows being added to the mySQL database) however the ajax call times out from what I gather since after 60 seconds I see this in the console:
Error: Gateway 504 timeout.
Even with the timeout, I can see that the php script is indeed still working in the background and still adding rows to the database.
I did try increasing timeout and set_time_limit(0)
in my code and still no luck. I think, based on my resourcefulness, I need to resort to long polling. Here is my modified javascript, trying to implement long polling;
$("#scan_library_submit").on('click', function(e){
var media_dir = $("#media_dir").val();
var media_ext = document.forms['scan_library_form'].elements[ 'media_ext[]' ];
if( media_dir =='' || media_ext == '' )
{
document.getElementById("scan_library_response").innerHTML = '<font color="red"><i class="fas fa-times"></i> All Fields Required.</font>';
return
}
this.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Scanning...';
//ajax call to scan library
(function scan_media_library(){
setTimeout(function(){
$.ajax({
url: 'ajax/library_scan.php',
type : "POST",
dataType : 'json',
data : $('#scan_library_form').serialize(),
success : function(result) {
if(result.code === 404){
document.getElementById("scan_library_response").innerHTML = result.msg;
return;
}else if(result.code === 200) {
document.getElementById("scan_library_response").innerHTML = result.msg;
document.getElementById("scan_library_submit").innerHTML='<i class="fas fa-check"></i> Complete!';
setInterval('window.location.reload()', 9000);
return;
}else{
scan_media_library();
}}
})
}, 3000);
})();
});
I still get the Error Gateway 504... :(
also, a bit of an aside in this question. I would like to update a <span>
with progress as the script runs; basically this script is adding data to a mysql table, so it could ping the table for row counts periodically. Would that be possible to implement? If so...how? Links to appropriate tutorials are appreciated, this is a learning experience to me! As the AJAX request runs, it can ping the table every 3-5 seconds to see how many rows are added, then refresh a <span>
with the result.