title: PhantomJS hanging when called from CLI or Web
body: <p>I'm trying to use phantomJS to capture a screenshot of a URL, however when I call phantomJS (from either the command line or web app) it hangs and seesm to never execute the "exit()" call.  I can't seem to find any error messages and it remains running until I kill it.  This is the JS file that is passed to the phantomjs command:</p>
  
  <pre><code>var page = require('webpage').create();
  var system = require('system');
  var script_address = '';
  var page_to_load = '';
  var members_id = '';
  var activities_id = '';
  var folder_path = '';
  
  if (system.args.length &lt; 5) 
  {
      console.log('Usage: phantom_activity_fax.js script_address page_to_load members_id activities_id folder_path');
      console.log('#Args: '+system.args.length);
      phantom.exit();
  }//END IF SYSTEM.ARGS.LENGTH === 1
  
  //ASSIGN OUR ARGUMENTS RECIEVED
  script_address = system.args[0];
  page_to_load = system.args[1];
  members_id = system.args[2];
  activities_id = system.args[3];
  folder_path = system.args[4];
  
  console.log(system.args[0]);
  console.log(system.args[1]);
  console.log(system.args[2]);
  console.log(system.args[3]);
  console.log(system.args[4]);
  
  //OPEN OUR PAGE WITH THE VALUES PROVIDED
  page.open(page_to_load, function () {
      console.log("Entering Anonymous Function, Beginning RENDER:\n");
      page.render(folder_path+members_id+'_'+activities_id+'.png');
      phantom.exit();
  });
  </code></pre>
  
  <p>I see the values pushed to the console, but after that it just hangs :( I've tried the web inspector, but could not understand where to execute the __run() call, and didn't see any change when I added the debugger-autorun=yes to the call :(.</p>
  
  <p>This is the output I get from the command line when it hangs (as root user):</p>
  
  <pre><code>[root@wv-wellvibe2 faxes]# phantomjs /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php 397 0 /var/www/wv-wellvibe2-test/uploads/images/faxes/
  /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js
  https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php
  397
  0
  /var/www/wv-wellvibe2-test/uploads/images/faxes/
  </code></pre>
  
  <p>And this is the output I get when running it as my own user, but I don't see the image file in the designated folder (faxes):</p>
  
  <pre><code>[user@wv-wellvibe2 ~]$ phantomjs /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php 397 0 /var/www/wv-wellvibe2-test/uploads/images/faxes/
  /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js
  https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php
  397
  0
  /var/www/wv-wellvibe2-test/uploads/images/faxes/
  Entering Anonymous Function, Beginning RENDER:
  [user@wv-wellvibe2 ~]$ 
  </code></pre>
  
  <p>Unfortunately, as I said, the command completed but did not save a .png in the faxes folder.  Here is the permissions for that folder:</p>
  
  <pre><code>[root@wv-wellvibe2 faxes]# ls -la
  total 12
  drwxr-xr-x 3 root   apache 4096 May 16 15:31 .
  drwxr-xr-x 5 apache apache 4096 May 16 14:14 ..
  drwxr-xr-x 6 apache apache 4096 May 20 15:05 .svn
  </code></pre>
  
  <p>Please let me know if there is anything else I can provide!
  Thank you!</p>
  
  <p>(As requested here is the PHP script that calls the Phantom JS process)</p>
  
  <pre><code>header("Date: " . date('Y-m-d H:i:s'));
  //GET THE SMARTY CONFIG
  include_once $_SERVER['DOCUMENT_ROOT'] . "/smarty/configs/config.php";
  
  //VARS USED LATER
  $process_script = $_SERVER['DOCUMENT_ROOT'] . '/javascripts/phantom_activity_fax.js';
  $page_to_load = 'https://' . $_SERVER['HTTP_HOST'] . '/manual_scripts/phantom_js_test_page.php';
  $members_id = $_SESSION['members_id'];
  $activities_id = 0;
  $folder_path = $_SERVER['DOCUMENT_ROOT'] . 'uploads/images/faxes/';
  $system_response = '';
  
  
  $call = "phantomjs --remote-debugger-port=65534 --remote-debugger-autorun=yes " .  $process_script . " " . $page_to_load . " " . $members_id . " " . $activities_id . " " . $folder_path;
  
  echo 'CallingSystemWith: ' . $call . '&lt;br /&gt;';
  
  try 
  {
      $system_response = system($call);
  
      echo '&lt;br /&gt;SystemResponse: ' . $system_response . '&lt;hr /&gt;';
  } catch (Exception $exc) {
      echo $exc-&gt;getTraceAsString();
  }//END TRY / CATCH
  </code></pre>
  
  <p>(The page it tells PhantomJS to "scrape" is a simple PHP script that outtputs a print_r() of $_SESSION and $_REQUEST)</p>