views:

82

answers:

2

I have a problem. I have made a script to convert a given HTML page (url) to a given jpg file using html2image:

#!/bin/sh
cd /absolute/path/html2imagev3
LD_LIBRARY_PATH=.:/usr/lib:$LD_LIBRARY_PATH xvfb-run ./html2image $1 $2

It is then run like this:

/path/to/convert 'http://www.google.com' /tmp/google_screen.jpg

This works without problems. When I call this script using PHP, however,

system('./convert ' . $url . ' ' . $file);

I get this error:

Xlib:  extension "RANDR" missing on display ":99.0".
current dir: /absolute/path/html2imagev3/libxpcom.so
Failed to get HOME

How can I fix this problem?

Edit: I have fixed it. Thanks for the help. By adding a HOME var to the convert script the program runs:

HOME=/tmp LD_LIBRARY_PATH= ...
+1  A: 

Well, your xvfb-run script will launch Xvfb, an X Virtual FrameBuffer, which is essentially an X11 server with no attached display. The X11 protocol has many extensions, which not all X servers support. In this case your html2image script is asking for a given extension (the RANDR, or "R and R" extension, as Pekka points out) and can't find it.

If this works when logged in as your user, and not when you're running from PHP, it's probably because your PHP script is getting executed with a different environment. I don't know all the environment variables that may affect Xvfb, but it seems like you might want to try explicitly enabling the RANDR extension, perhaps with something like:

xvfb-run -s "+extension RANDR" ./html2image $1 $2
Daniel Pryden
-s "+extension RANDR" does not help. Thanks anyway.
VDVLeon
The point is still valid, though, that something about the environment you're running PHP under is causing different behavior from Xvfb. Without more information about your computer's environment, I can't magically deduce what might be the problem.
Daniel Pryden
I am running a Debian 4 server (no X11 server installed). That's why I use Xvfb. But what is relevant about my computer environment?
VDVLeon
"Environment" as in "environment variables". That's the most likely thing to be different between running as your user and running under Apache (probably as the "nobody" user).
Daniel Pryden
In /etc/X11/Xwrapper.config there one rule: allowed_users=consoleI changed this to anybody, bit that didn't help either.
VDVLeon
A: 

Just settings the HOME var in the startup script was the solution.

VDVLeon