I want to execute PhantomJS from PHP on localhost.
Can any body explain how to execute PhantomJS from PHP and what package I should download from phantomjs.org?
Go to the “bin” folder and check phantomjs.exe file. If you are using it on a Windows OS, then you can set the path variable under the environment variable for fast access through command prompt. The command to run the PhantomJS program: C:\> phantomjs [options] file.
PhantomJS is a headless web browser scriptable with JavaScript. It runs on Windows, macOS, Linux, and FreeBSD. Using QtWebKit as the back-end, it offers fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
chmod +x
)$response = exec('/path/to/phantomjs myscript.js');
There's actually a library called PHP PhantomJS, intended to make this easier for you!
PHP PhantomJS is a flexible PHP library to load pages through the PhantomJS headless browser and return the page response. It is handy for testing websites that demand javascript support and also supports screen captures.
Full documentation
Feature list :
- Load webpages through the PhantomJS headless browser
- View detailed response data including page content, headers, status code etc.
- Handle redirects
- View javascript console errors
- View detailed PhantomJS debugged information
- Save screen captures to local disk
- Set viewport size
- Define screen capture x, y, width and height parameters
- Delay page rendering for a specified time
- Execute PhantomJS with command line options
- Easily build and run custom PhantomJS scripts
Make sure, though, that your version of PhantomJS is compatible with your version of PHP PhantomJS:
Please Note: Version 4.0 of this library is currently waiting on an unresolved issue with PhantomJS 2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With