Installing PhantomJS on the server

I am using PhantomJS on Windows and accessing files via command line. Now I want to install it on the server I am running on localhost, so I want it to be installed on Apache so that I can integrate Phantom with my html and PHP to be used in the web page. I am using Windows 8.1 and Apache Server for localhost.

Can I do it? How do I use it in web services now? How will I use it if I need to make my own online network? should i ask my hosting provider to host this thing on a server for me?

I am using phantomJS to develop a web service that takes a url as input and returns an image file in a screenshot of the website.

+3


source to share


2 answers


The PhantomJS "install" simply adds its path to the PATH environment variable.

Running through php

Since you are using php, you will be calling PhantomJS from your php script as shown here , where you need to provide the full path to the PhantomJS executable. You can also use putenv

to extend PATH directly from php as shown here .
You can return something from a PhantomJS script to a variable $output

exec

and then parse it.

Running through the web server module



PhantomJS provides a web server module . You can write a script that listens for requests, builds page

on request, and returns an image. You run the script somehow on startup or along with apache. It is also possible to write a shell so that you can run it as a Windows service. It might be possible to pass requests through Apache so that PhantomJS is not completely open to the outside.
Although this option is a bit treacherous, because PhantomJS can fail and then you need some kind of respawn mechanism. Your script can also handle memory leaks.

Return image

Both of the above options are independent of how you return the image. There are several possibilities.

+5


source


//throws a lot of errors because searching some libraries
$cmd = 'unset DYLD_LIBRARY_PATH ;';
$cmd.= ' /abs/path/to/phantomjs';
$cmd.= ' /abs/path/to/script.js';

//set environment variable to node source
putenv('PATH=/abs/path/to/node/bin/');

//now exec the cmd and pipe the errors to stdout
exec($cmd.' 2>&1', $output);

//and output the results
print_r($output);

      

here is the answer from the above url. I changed it to match mine.

<?php

$cmd = ' ./ScreenShotWeb/phantomjs';
$cmd.= ' ./ScreenShotWeb/shot.js';

putenv('PATH=./ScreenShotWeb/');

exec($cmd.' 2>&1', $output);

print_r($output);
?>

      



I am trying to run this but it gives this: put

Array ([0] => '.' Is not recognized as internal or external command, [1] => operating program or batch file.)

in my root folder (C: / xampp / htdocs) there is a ScreenShotWeb folder where I placed the EXE from PhantomJS + all files.

0


source







All Articles