I have this following code:
$(window).load(function()
{
$('#content1').load('database.php');
setInterval (function()
{
$.post('status.php', { id: '1'}, function(responseText, responseStatus)
{
$('#content2').html(responseText);
});
}, 5000);
});
Basically, I am calling the database.php to do some database insertions, and using a periodic interval to get the status of its progress. The problem is that during the insertions, the interval posts are giving me request timeout error. Only once the database.php has finished processing, text in the content2 is written.
For now I am using very simple code in status.php file, just to see if I can get a response while the database.php is being processed. Here is the code (very simple):
<?php
echo "hello";
?>
I dont know why I am getting a timeout error and not getting an response. As you can see, in the statuse.php file, I am not using any php session variables which can block the calls. The funny thing is that once the processing of the database is complete, I do get a response. That is, I get the text ‘hello’.
The problem was that my service was only using one dyno. Since the database processing takes some time and is handled by my single dyno, the other AJAX request couldn’t be handled. To allow concurrency, more dynos are required.
This however, is not encouraged as one would be needing a dyno for each user currently using the service, plus an another dyno to handle the simple AJAX requests. It is encouraged to use workers (for example IronWorker that Heroku supports) so that these long processes would not result in having your dynos busy to the extent of not handling other requests.