0

I have a following php script -

<?php
$command = "python webkit2png/webkit2png -D screenshots http://stackoverflow.com";
$command = escapeshellcmd($command);
system($command);

When run from Terminal by means of

php test.php

it produces the website screenshots, however, opening test.php in browser does not bring any results.

Both python and php scripts are owned by _www user, under which apache is running. I even tried running the test.php under _www in Terminal, it still works. Is there something I'm missing?

Thanks to @amccausl I found this in apache logs -

Wed Feb 27 07:12:03 mini.local python[83331] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
Traceback (most recent call last):
  File "webkit2png/webkit2png", line 353, in <module>
    if __name__ == '__main__' : main()
  File "webkit2png/webkit2png", line 324, in main
    AppKit.NSBorderlessWindowMask, 2, 0)
objc.error: NSInternalInconsistencyException - Error (1002) creating CGSWindow
Ivan Vashchenko
  • 1,214
  • 2
  • 11
  • 19
  • You should check your apache error log. But you can also try sshing to your own box to run on command line (to isolate any problems with trying to render webkit without a terminal attached). – Alex M Feb 27 '13 at 03:26

3 Answers3

1

The library you're using is trying to establish a connection to your xserver to render a png. This works fine on terminal, because you have a connection available, but will break for ssh or apache sessions because they don't.

You can create one for their use with xvfb

The approach used in this question is a good example for you (you can ignore the solutions).

<?php
$command = "xvfb-run -a -s '-screen 0 640x480x16' python webkit2png/webkit2png -D screenshots http://stackoverflow.com";
$command = escapeshellcmd($command);
system($command);
Community
  • 1
  • 1
Alex M
  • 3,506
  • 2
  • 20
  • 23
0

you should use the absolute path like /usr/local/php53/bin/php

0

If you're not forced to use python and can install something else, I'd recommend http://phantomjs.org/. It's much better and powerful in making screenshots of webpages and doesn't need an xserver (but node.js)