2009-07-23 10:02
浏览 36


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:

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.


图片转代码服务由CSDN问答提供 功能建议

我正在为内部R&amp; D项目构建网页截屏应用程序。

环境:Ubuntu 9.04(默认桌面安装),Apache,PHP。

到目前为止,我有一个带有一个参数(URL)的bash脚本,启动firefox ,抓取屏幕并将其保存为PNG。 我试过从终端运行它,它运行正常。


 #!/ bin / bash \  nfirefox $ 1#启动firefox并转到传入的URL 
scrot -d 5 test.png#抓取屏幕抓取5秒延迟

接下来我创建了一个简单的 使用shell_exec运行脚本的PHP页面:

 $ url ='http://www.google.com';  
 shell_exec('sh script.sh'。$ url); 
 echo'&lt; img src =“test.png”/&gt;'  ; 

但是,当调用PHP页面时,屏幕未被捕获。 快速查看apache错误日志显示以下消息 :

giblib错误:无法打开X显示。 它*是*正在运行,是的

我猜这是因为apache是​​以不同的用户身份运行而无法访问 到我的X显示器。



  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题