title: PHP exec() performance
body: <p>The following PHP code does return me a runtime of about 3.5 seconds (measured multiple times and averaged):</p>
  
  <pre><code>$starttime = microtime(true);
  exec('/usr/local/bin/convert 1.pdf -density 200 -quality 85% 1.jpg');
  $endtime = microtime(true);
  $time_taken = $endtime-$starttime;
  </code></pre>
  
  <p>When i run the same command over a ssh terminal, the runtime is reduced to about 0.6 seconds (measured with the command line tool <code>time</code>).</p>
  
  <p>The version of the imagemagick library is</p>
  
  <pre><code>Version: ImageMagick 6.7.0-10 2012-12-18 Q16 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
  Features: OpenMP
  </code></pre>
  
  <p>What could be the reason for this time difference?</p>
  
  <p>One answer to a similar question here on stackoverflow was that the overhead comes from the Webserver having to start a thread/shell. Could this be really the reason? I thought threads are leightweight and don't take long at all to start/terminate.</p>
  
  <p>Prior to calling <code>exec</code> i set the number of threads used by imagemagick (because this was/is a bug in OpenMP?, <a href="http://www.daniloaz.com/en/617/systems/high-cpu-load-when-converting-images-with-imagemagick/" rel="noreferrer" title="Link">Reference</a>) to 1 with <code>exec('env MAGICK_THREAD_LIMIT=1');</code>. The runtime from PHP does not change much, no matter what value i set for <code>MAGICK_THREAD_LIMIT</code>. Anyway there does not seem to be a bug in OpenMP on in this version because the runtime of the command line execution is ok.</p>
  
  <p>Any suggestions of how i could improve the runtime of the above command would be greatly appreciated.</p>
  
  <p>Thank you very much for your help.</p>