views:

213

answers:

2
+4  Q: 

PHP and Xvfb

I'm trying to execute firefox on a headless server to take screen shots of a website. I can do this fine from the terminal using

"DISPLAY=:12 firefox -saveimage http://www.google.com/".

The problem is when I try to do system("DISPLAY=:12 firefox -saveimage http://www.google.com"); doesn't work. I have a feeling that it's not executing in a normal shell environment. I went against my better judgment and gave the apache user an actual shell. If I su to apache and execute the command everything is fine and works as expected, but again it doesn't work from a system call. Any insight is very welcome.

A: 

Most likely there's some dependency on the environment variables you have set up as a shell user that isn't fulfilled by the httpd's environment. Before doing any heroics with the environment, though, I'd recommend capturing stderr from your job (adding 2>/tmp/imgcaperrlog to the end of it, for example) and seeing if it's making any complaints.

chaos
I gave that a shot and it didn't work =\
William
Okay, second version up.
chaos
I tired that and it's not even executing. That's what made me think maybe the environment that php executes system calls in is some how different.
William
Yeah, it's definitely different. What you're doing is an X operation, so it'll depend on all the context going on there. One thing you can do is compare your shell environment (**set** by itself to view) with the environment inside your script (**print_r($_ENV)** or something similar).
chaos
+1  A: 

I found the solution.

I just needed to create a shell script that will call that for me. After playing with it for a while I got it working after adding "export HOME="/var/www/"" at the top of the script.

I hope this helps someone else.

William
+1 for following up with the solution
Ryan Graham