3

I'm using the following code on a linux web server

$error = exec('phantomjs table1.js', $op, $code);
echo $code; // prints 11 on screen

table1.js

var page = require('webpage').create();
var url = 'table1.php';
page.open(url, function (status) {
    page.render('ss/table1.png');
    phantom.exit();
});

table1.php

echo '<h1>This should be converted to an image</h1>';

I went through this link but that code isn't listed there. Any idea what this exit code stands for?

asprin
  • 9,579
  • 12
  • 66
  • 119

2 Answers2

2

Code 11 is a "segmentation fault": A segmentation fault (also segfault) is caused by a program when it tries to allocate data in a piece of memory that is not assigned to the program. It indicates a program error and usually (if not always) crashes the program. In your case, the segfault probably is caused by phantomjs, which indicates perhaps an old or beta version.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • Hmm..that's strange. `table1.js` doesn't have any code outputting `11` in it. – asprin Apr 24 '13 at 11:37
  • I just have those two lines listed above in the file (let's call it `abc.php`) When I run `abc.php`, I get `11` shown on screen. Are you referring to what's inside `table1.js`? – asprin Apr 24 '13 at 11:39
  • It's a binary file which helps to create screenshots of the page being rendered (In my case, output of `table1.php`). More info [***here***](http://phantomjs.org/) – asprin Apr 24 '13 at 11:49
  • I copied your `table1.js` into mine, and it worked fine (even though nothing gets rendered). – Bart Friederichs Apr 24 '13 at 12:29
  • This exact same code works on my localhost too...the problem is with the production server – asprin Apr 24 '13 at 12:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28805/discussion-between-bart-friederichs-and-asprin) – Bart Friederichs Apr 24 '13 at 12:30
  • @BartFriederichs how did you make it work as I am in the same situation now. It works If I run phantom command on server but returns 11 if i run using php exec. :( – Damodar Bashyal May 02 '16 at 05:55
0

This is what I found out.

  • Your phantomjs is calling some child process. (My assumption would be you are executing this on node).
  • Now, if table1.js exits abruptly, then return code will be binary 00001000 and the main process(node as per assumption) will also exit with the same binary error code.
  • Now as per exit status co-relation, both the binaries will be converted to normal sign signals which makes both to be 1 and 1.

Hence your error code of 11.

Source: Are there any standard exit status codes in Linux?

Community
  • 1
  • 1
Srihari
  • 766
  • 1
  • 6
  • 22
  • According to that thread, segmentation faults results in the code `11`. I had this segmentation fault listed in my server error log. Any idea why or what the segmentation fault is? – asprin Apr 24 '13 at 11:57
  • It is `resource not found`. Check the segmentation fault description [here](http://www.cyberciti.biz/tips/segmentation-fault-on-linux-unix.html) – Srihari Apr 24 '13 at 12:58
  • @asprin If you are trying to save the output of a PHP file, host it on a server and provide a complete URL. I tried out the google image capture script and it worked. So I can say this thing will work. My suggestion is host in on your local and provide a complete path like `http://localhost/table1.php` and then modify your js to fetch from this path. – Srihari Apr 24 '13 at 13:02