title: How to run memory intensive PHP tasks (image conversion and OCR)?
body: <p>I'm sure if this kind of Q is allowed in StackOverflow, but I'm mostly looking for advice.</p>
  
  <p>I have a web app which accepts PDF uploads, converts them to a TIFF, then OCRs them with Tesseract.</p>
  
  <p>These PDFs are 50 - 200+ pages long. My server completes this for PDFs less than 6 pages.</p>
  
  <p>The resultant TIFF is 1.2GB. The PDF was only 98KB. We have some PDFs which are already hundreds of MBs, so who knows what they'll end up as once converted. This size seems wrong, but let's table it for now.</p>
  
  <p>Once we start talking about 200 page PDFs, nothing works. I get the error:</p>
  
  <pre><code>exec(): Unable to fork [tesseract '/home/forge/default/storage/app/ocr/1.tiff' /tmp/tesseractbO7aur -psm 3  2&gt;&amp;1]
  </code></pre>
  
  <p>The TIFF conversion works OK, even with large PDFs. But Tesseract always gives this error when PDF is more than ~6 pages.</p>
  
  <p>Perhaps I just need a lot more memory. My questions are:</p>
  
  <p><strong>How can I determine what the limit/max being hit is?</strong> How do I know if this is a RAM issue, a CPU issue, something else?</p>
  
  <p><strong>How would you run this?</strong> Should I keep this on our web server and just significantly increase the spec? Or would you make another machine dedicated to producing the OCRs? They don't need to be instant in response to user events - it's fine if they upload and the OCR takes a few hours even. I'm used to apps which need a lot of power just taking a long time, not dying entirely. I'd be fine with the OCR taking a very long time, just so long as the process doesn't just fail.</p>
  
  <p>I've only ever worked on simple web apps where the user makes a request and a page is displayed. I'm not used to this sort of stuff. I am using Laravel for the app, so I have access to Redis queues etc if they should be used. I'm using Nginx on AWS. I did consider AWS Lambada but I don't think this can achieve what I need.</p>
  
  <p>Thanks, and I hope someone can help.</p>
  
  <p>Sam</p>