I'm using phantomJS for the purposes of programmatically taking screenshots of a webpage. My webserver runs on Linux 64 bit.
The Scenario
My test.php
file
exec('./phantomjs --version', $o, $e);
print_r($o);
echo $e;
I open test.php
in a browser. The out put I get is:
1.9.1 // version number
0 // exit code
This proves that I can run commands through exec()
and phantomJS
is working perfectly.
The Issue
Now when I replace the above code with:
exec('./phantomjs http://mywebsite.com/test.js', $o, $e);
print_r($o);
echo $e;
The output is:
Array ( ) // empty output
139 // exit code which on investigating turned out to be segmentation fault
I also tried:
exec('./phantomjs ./test.js', $o, $e); // since phantomjs and test.js are in same folder
but the result was the same (segfault)
test.js code:
var page = require('webpage').create();
var url = 'http://www.rediff.com/';
page.open(url, function (status) {
phantom.exit();
});
This makes me believe that using the full path as the second argument of phantomJS
is causing it to crash. Thus, the things that I'm wondering are:
- Am I right in my assumption?
- Or is it because of some restriction on my webserver which is blocking
exec()
from accessing the.js
file through absolute URL?