Reputation: 118
I'm building a web page screen capture application for an internal R&D project.
Environment: Ubuntu 9.04 (default desktop install), Apache, PHP.
So far I've got a bash script that takes one parameter (URL), fires up firefox, grabs the screen and saves it as a PNG. I've tried running this from terminal and it works fine.
Here's the Bash script:
#!/bin/bash
firefox $1 # Start firefox and go to the passed in URL
scrot -d 5 test.png # Take screen grab with 5 second delay
Next I created a simple PHP page that uses shell_exec to run the script:
<?
// Sample URL
$url = 'http://www.google.com';
// Run the script
shell_exec('sh script.sh ' . $url);
// Out put HTML to display image
echo '<img src="test.png" />';
?>
However, when the PHP page is called the screen is not captured. A quick look in the apache error logs show the following message:
Error: no display specified giblib error: Can't open X display. It *is* running, yeah
I'm guessing this is because apache is running as a different user and hasn't got access to my X display.
So, can anyone shed any light on what I'm doing wrong or how I can capture the current user display.
Thanks.
Upvotes: 1
Views: 2724
Reputation: 4814
Here is a guide to do screen-capturing using firefox and xvfb. The advantage with this approach is that there will be no firefox windows opening and closing on your main X server. It will also solve your problem with permissions.
Upvotes: 2
Reputation: 401162
Launching firefox from PHP running under Apache seems to me like a bad idea (it definitly feels wrong).
The way I would do that :
With this system, several advantages :
It's not really an answer to the question, but I think it's a better way... Hope this helps !
Upvotes: 2