title: PHP + PhantomJS Rasterize
body: <p>I'm using PhantomJS 64 bit in my PHP application to dynamically capture an HTML page to be emailed to the user.</p>
  
  <pre><code>phantomjs rasterize.js "http://..." /path_to_images/image.png
  </code></pre>
  
  <p>This method works fine when I run the above on the command line but when the PHP script runs the command using <code>exec</code> it fails with no output and returns exit code 11.</p>
  
  <p>If I switch it to use the 32 bit phantomJS binary, the command succeeds but fails to load the google JSAPI on the page since with error <code>Reference Error: can't find variable google</code>.  This is a problem because not all of the page content is loaded and captured as an image.  The JSAPI is included using HTTPS.  If I switch to HTTP, the reference error is gone but the rendered image comes out all black.</p>
  
  <p>I tested the command as the same user that php is running as.</p>
  
  <p>To sum it up:</p>
  
  <pre><code>command&gt; phantomjs_64 rasterize.js "http://..." /path_to_images/image.png
  </code></pre>
  
  <p>OK</p>
  
  <pre><code>exec('phantomjs_64 rasterize.js "http://..." /path_to_images/image.png');
  </code></pre>
  
  <p>No Output, Exit Code 11</p>
  
  <pre><code>command&gt; phantomjs rasterize.js "http://..." /path_to_images/image.png
  exec('phantomjs rasterize.js "http://..." /path_to_images/image.png');
  </code></pre>
  
  <p>Incomplete Output</p>
  
  <p>Does anyone know why the default phantomJS rasterize.js script would fail when running on PHP or have a workaround for this?</p>