Sunday, 15 May 2011

jquery - PHP/Ajax PDF generation timeout -


I have a code in PHP / ajax / jquery, so documents with values ​​from the database can be prepared. But when the user wants to create a large number of PDF and word files, then I have a problem with the time required to generate large numbers of files.

Creating files for mySQL database from the line ID that I want to create a PDF or word from every element works well, I have used: and MPDF.

1 file creation ~ 2-3 seconds when user can generate 500 records and wants to pack it in .zip, then I have a problem.

My code looks like this:

I am sending it to the client side by creating an AJAX call:

  function () {var Ids = new array (); $ .AJX ({type: 'post', url: 'ajax / generate_pdf.fpp', data: {'filename': $ ("# filename"). Val (), 'idPDF': ids.toString ()} $ ("#"); $ ("#moded") .app ("Loading" .br />); $ ("#moded") .Append (Data);}) .file (function () {Warning ("Error ..");}); }  

My generic_pdf.php file looks like this:

   

You have a problem with the request timeout. Either you can:

  1. To avoid having maximum time to run the script, tell your php, going from 0 to the following function:

      set_time_limit 0);  

  2. Refactor your code so that the customer will have 1 Ajax un 2 for every 2 seconds. The request will send the request, and the server always generates 1 PDF each request.

  3. The above two options will wait a very long time for the customer. You can do whatever you can, Google drives the same way when you try to upload a large file, it will notify you at the end of the process (by email, for example) . UD For databases in the database, you can make your call queue ID of PDF documents to make calls, and then run through a cron job queue and actually generate it so that the user is free from the "loading" screen To be. When your (async) process is finished, inform the client via email, if available, or any other option that is appropriate for your user case.


No comments:

Post a Comment