0

I'm working on a business app which relies on batch PDF document creation.

At a certain time my app has to create dozens of PDF files and this makes the script timeout...

I do not have any access to the "set_time_limit" parameters on my hosting.

For now I rely on manual action : my script runs for 5 files, then stops. I refresh the browser page, relaunch the script for 5 other, and so on. This is not a reliable solution as the user must stay focused and periodically hit refresh !

I'm looking for a solution that would "replace the manual user action". PHP doesn't seem to be the solution (due to the timeout limits). Would jQuery be the answer ?

How ?

I searched for "long polling" or "long running" topics but didn't get any solution that would fit.

Thanks for the help !

4
  • 1
    jQuery doesn't timeout, the server proccess does, and the only way to fix that is to change it in PHP, there's nothing jQuery can do with that !
    – adeneo
    Feb 28, 2014 at 8:19
  • you can use set_time_limit(0); in PHP and if you want to call it in the browser, then close your browser once it is running use ignore_user_abort(true);
    – CodeBird
    Feb 28, 2014 at 8:20
  • Use the set_time_limit() function. Feb 28, 2014 at 8:21
  • 1
    Use a background service on the target OS for this and communicate with that using PHP instead, otherwise you'll run into all sorts of issues Feb 28, 2014 at 8:21

3 Answers 3

1

It will never be a nice solution. But the way you want to solve it is possible. But still not recommended :)

function callBackup() {
    $.ajax({
        url : 'backup.php',
        success : function(response) {
            // Simple check if backup processed all files
            if (response != '1') {
                // Run backup again
                callBackup();
            } else {
                alert('Backup done');
            }
        }
    });
}

Your script at the server needs to echo '1'; if you have processed everything.

0

I don't think @KoalaBear's solution will work. It is PHP that is timing out not Jquery.

Set_time_limit(0) is easiest way to get around this.

Another solution is to delegate this timing consuming task to a background process.

check Gearman

A good example of background job

But if you use Gearman you have to periodically polling the server to check the status of the Job

0

You can do this by background workers. Look into intoGearman, Redis resque or celery task queues. Don't let your client wait.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.