0

I am trying to run PhantomJS on my server hosted by HostGator. Phantom is initiated by a shell script that:

  1. Initializes Phantom JS and passes in the script to execute and
  2. Passes in three variables.

This code has worked perfectly fine on my Xampp Server, but began giving me trouble as soon as I uploaded the entire project to hostgator. I have been able to verify that, up until this script is called, everything operates the way it was designed to. Here is the script that initializes PhantomJS:

<?php  
$URL = $_POST['url'];
$USER = $_POST['user'];
$PASSWORD = $_POST['password'];

$res = shell_exec("...EXACT PATH/scripts/phantom/bin/phantomjs ...EXACT PATH/scripts/phantom/examples/test.js 2>&1 $URL $USER $PASSWORD");
echo json_encode(preg_replace("/[^A-Za-z]/", '', $res));
?>

All of the variables are properly passed into this script. When called, the console prints the following (this is its raw form minus the path to the files)

xbxffdddliblibcsolibcstartmainxfdxffdddxaPhantomJShascrashedPleasereadthebugreportingguideathttpphantomjsorgbugreportinghtmlandfileabugreport

Or, with spaces added,

PhantomJS has crashed. Please read the bug reporting guide at http://phantomjs.org/bugreporting.html and file a bug report

I was told by Hostgator reps that the server itself is 64 bit, and I have made SURE to upload the correct version to the server. I have done some research on Hostgator servers, and have found the max timeout time for PHP scripts is 30 seconds--this throws the error usually within 2.

Any ideas as to why this is happening?

Ethan
  • 1,905
  • 2
  • 21
  • 50
  • Use exec instead of shell_exec, it will let you get the exit code when phantom dies, that will help give more information for your question. http://php.net/manual/en/function.exec.php – chiliNUT Jun 08 '17 at 00:09
  • @chiliNUT One second while I make this change. Will this exit code automatically be echoed into the console? Simply making this changed resulted in `httpphantomjsorgbugreportinghtmlandfileabugreport` being printed to the console. – Ethan Jun 08 '17 at 00:16
  • no, read the doc on exec, it assigns the exit code to the 3rd arg passed to exec – chiliNUT Jun 08 '17 at 01:06
  • @chiliNUT that doc was confusing to me, should I modify the code to look like this? `exec("...EXACT PATH/scripts/phantom/bin/phantomjs ...EXACT PATH/scripts/phantom/examples/test.js 2>&1 $URL $USER $PASSWORD", $output);`??? – Ethan Jun 08 '17 at 01:12
  • Exec doesn't output anything afaik, it just sends crap to variables. First arg is the command, second arg is a var that receives the output of the command, as an array split by lines, which you don't care about, 3rd arg is the exit code. So you want like: `exec("your command",$dummyVar,$exitCode);echo $exitCode;` – chiliNUT Jun 08 '17 at 02:41

0 Answers0