ariya / phantomjs

Scriptable Headless Browser
http://phantomjs.org
BSD 3-Clause "New" or "Revised" License
29.45k stars 5.76k forks source link

Crashes from PHP but not from the terminal #14167

Closed micahstairs closed 4 years ago

micahstairs commented 8 years ago

Running this PHP from my server <?php shell_exec('./phantomjs hello.js 2>&1'); ?> gives:

1   0x1b67967 ./phantomjs() [0x1b67967]
2   0x1baaaf5 ./phantomjs() [0x1baaaf5]
3   0x198c463 ./phantomjs() [0x198c463]
4   0x1ab3982 ./phantomjs() [0x1ab3982]
5   0x79abb9 ./phantomjs() [0x79abb9]
6   0x76b6f9 ./phantomjs() [0x76b6f9]
7   0x750a5d ./phantomjs() [0x750a5d]
8   0x41cd89 ./phantomjs() [0x41cd89]
9   0x41f5c4 ./phantomjs() [0x41f5c4]
10  0x415b86 ./phantomjs() [0x415b86]
11  0x7f0aa1c26d5d /lib64/libc.so.6(__libc_start_main+0xfd) [0x7f0aa1c26d5d]
12  0x4176a1 ./phantomjs() [0x4176a1]
PhantomJS has crashed. Please read the bug reporting guide at
 and file a bug report.

Running from the terminal (by SSHing into the server) ./phantomjs hello.js does not crash and gives the expected output: Hello, world!.

Contents of hello.js:

"use strict";
console.log('Hello, world!');
phantom.exit();
zackw commented 8 years ago

We have a bunch of reports of divergent behavior between PhantomJS run under a terminal and run under PHP shell_exec. We haven't been able to pin any of them down, probably because of differences in PHP configuration. Yours is nice and simple, so would you mind doing some experiments for us?

  1. Does <?php shell_exec('./phantomjs hello.js < /dev/null 2>&1'); ?> crash?
  2. Does ./phantomjs hello.js 2>&1 | cat crash?
  3. What does <?php echo exec('tty') ?> print?
  4. What does <?php passthru('lsof -p $$')?> print?
  5. What does <?php phpinfo()?> print?
  6. Exactly what version of PhantomJS are you using?

We may have more experiments for you to try based on the results of this.

micahstairs commented 8 years ago

Great, thanks for your prompt reply! I can definitely work with you to narrow this down.

  1. This does not seem to crash, but I'm not getting any output whatsoever, so maybe it is silently crashing?
  2. Running this from the terminal does not crash, no.
  3. Outputs not a tty.
  4. Outputs nothing.
  5. I get a really long page (it would take a lot of screenshots to capture the entire thing): image
  6. Version 2.1.1

NOTE: To get the output of running the PHP, I am uploading it to my website and accessing the PHP file from my browser. Let me know if you want me to do this a different way.

zackw commented 8 years ago

Thanks. (That was plenty of the phpinfo output.) Next experiment. Make sure gdb and gcc are installed on your server. Then compile this program on your server: notty-gdb.c using e.g.

$ gcc -g -O2 -std=c99 notty-gdb.c -o notty-gdb

and run it like this:

$ ./notty-gdb /path/to/phantomjs /path/to/hello.js

You will get a (gdb) prompt. Type signal SIGCONT and hit return. There will be a bunch of output, and then either something like [Inferior 1 (process NNNN) exited normally] or something like Program received signal SIGSEGV, Segmentation fault. If it's the first, type q to exit the debugger, then cat phantomjs.out. If it's the second, type bt to get a backtrace (hopefully with symbols this time) and then q and cat phantomjs.out. Either way, tell us what happened.

(You may have to rename the C source file after you download it. Sorry; Github is still being stupid about attachments to bug reports.)

micahstairs commented 8 years ago

I am afraid I do not have access to gcc.. https://support.ehost.com/articles/hosting-guide/hardware-software/compatible-technologies

zackw commented 8 years ago

That's very unfortunate; I do not know how to write that program in any other language (it does arcane terminal-related stuff that isn't possible in any high-level language I know).

zackw commented 8 years ago

Although ... what happens if you do

$ ssh yourserver /server/path/to/phantomjs /server/path/to/hello.js

or

$ ssh yourserver /bin/sh -c 'exec /server/path/to/phantomjs /server/path/to/hello.js < /dev/null'

from your local machine?

micahstairs commented 8 years ago

Both of those commands output: Hello, world!

mistegia commented 8 years ago

Same problem on hostgator shared server. Maybe I can add some info.

If I run via ssh "php index.php" that contains <?php echo shell_exec('./phantomjs hello.js 2>&1'); ?> I still get the "hello world".

Something is broken in apache?

Please let me know if I can contribute

stale[bot] commented 4 years ago

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!