在服务器上安装PhantomJS [英] Installing PhantomJS on server

查看:573
本文介绍了在服务器上安装PhantomJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 PhantomJS 在Windows上,并通过命令行访问文件。现在,我想我正在本地主机上的服务器上安装它,所以我希望它是在Apache安装,这样我可以幻影和我的HTML和PHP集成要在网页中使用。我使用的是Windows 8.1和Apache服务器的本地主机。

I'm using PhantomJS on windows and accessing the files through command line. Now I want to install it on the server I'm working on local host so I want it to be installed on Apache, so that I may integrate Phantom with my html and PHP to be used within a web page. I'm using Windows 8.1 and Apache Server for localhost.

其实我可以做到这一点?如何在现在的Web服务使用它?
如何我会使用它,如果我必须让我的网站在网上?我应该为T问我的托管服务提供商放置在服务器上这件事情对我?

Can I actually do that? How to use it in web services now? How i will use it if I have to make my web online? should I have t ask my hosting provider to place this thing on server for me?

我使用phantomJS开发一个Web服务,它接受一个URL作为输入并返回该网站的截屏的图像文件。

I'm using phantomJS to develop a web service which takes a url as input and returns an image file of the screen shot of the website.

推荐答案

该PhantomJS的安装只是把它的路径PATH环境变量。

The "installation" of PhantomJS is just adding its path to the PATH environment variable.

由于您使用的PHP,你会从你的PHP脚本像它显示的这里,你需要提供完整路径PhantomJS可执行文件。您还可以使用传给putenv 这里看到从PHP直接扩展的PATH 。结果
您可以从 EXEC ,然后的 $输出变量PhantomJS脚本返回一些分析它。

Since you're using php, you would invoke PhantomJS from your php script like it is shown here where you need to provide the full path to the PhantomJS executable. You can also use putenv to extend the PATH directly from php as seen here.
You can return something from the PhantomJS script in the $output variable of exec and then parse it.

PhantomJS提供 Web服务器模块。您可以编写侦听请求脚本,根据要求创建并返回图像。你会莫名其妙地在启动与Apache运行脚本或一起。它也可以编写一个包装,这样就可以作为Windows服务运行它。有可能通过的Apache请求,使得PhantomJS不向外界完全打开。结果
尽管此选项是有点奸诈,因为PhantomJS可能会失败,那么你就需要某种恢复机制。您的脚本也可能会遇到内存泄漏。

PhantomJS provides the web server module. You can write a script that listens for requests, creates the page on request and returns the image. You would somehow run the script at startup or together with apache. It's also possible to write a wrapper so that you can run it as windows service. It may be possible to pass the requests through Apache so that the PhantomJS is not completely open to the outside.
Although this option is a little treacherous, because PhantomJS may fail and then you would need some kind of reviving mechanism. Your script may also run into a memory leak.

上述两个选项是不可知的,你怎么回的影像。有几种possiblities

Both of the above options are agnostic to how you return the image. There are several possiblities.


  1. 在请求创建一个随机和唯一的文件名和 渲染 页面到文件中。然后,您可以发送文件的名称可能事后请求它的客户端。这需要两个请求。

  2. 在要求,通过 renderBase64 接收普通图像数据。现在,您可以直接在回复中发送此图像数据和客户端可以把它放入DOM通过 数据: -URI

  1. On request, create a random and unique filename and render the page into the file. You can then send the name of the file to the client which might request it afterwards. This needs two requests.
  2. On request, render the page through renderBase64 to receive the plain image data. Now you can send this image data directly in the response and the client may put it into the DOM via data:-URI.

这篇关于在服务器上安装PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆