title: How to make PHP wait until PDF is created for printed?
body: <p>I have a script that creates a PDF document and proceed to send it to be printed. It happens that I need to wait for the document to be created, check that and recently sent for printing.</p>
  
  <pre><code>    define('TIKET_DIR', public_path('temp/'));
      $token = sha1(microtime().'tk');
      $pdfPath = TIKET_DIR.$token.'.pdf';    
      $html2pdf = new HTML2PDF('V', array('72', '110'), 'es', true, 'UTF-8', 0);
      $html2pdf-&gt;WriteHTML($html);
      $html2pdf-&gt;Output($pdfPath, 'F');
      $cmd = "lpr -P".$ococina-&gt;impresora." ";
      $cmd .= $pdfPath;
      $response = shell_exec($cmd);
  </code></pre>
  
  <p>The variable $html is dynamically created and may be delayed. Usually PDF document printed, but sometimes it does not print and I think this happens because the lpr command is executed without the PDF document is ready. I use LEMP  on Ubuntu with CUPS print server. I have to turn off and turn on all printers connected to the computer and just the PDF document previously sent print.</p>
  
  <p>Thanks in advance.</p>