PhantomJS HTTP Client
By using this client you will execute the inner javascript code and make the DOM as real as in the true browser, that can be required for some search engines to work properly.
Notice about cookies
At the current state phantomJS adapter does not support internal cookieJar usage.
Installation
The client is available with the package serps/http-client-phantomjs:
$ composer require 'serps/http-client-phantomjs'
Additional requirement
PhantomJS binaries have to be installed to use the client. The process for installing it depends on your environment, you will find further guides on the internet.
The following PhantomJs version were tested with the library:
- 1.9.7
- 1.9.8
- 2.0.0
- 2.1.0
Note
The package jakoch/phantomjs-installer can help you to manage phantomJS as a dependency of your project.
Usage
use Serps\HttpClient\PhantomJsClient;
// The constructor accepts 1 optional parameter that is the path to the phantomjs binaries (default to 'phantomjs')
$client = new PhantomJsClient();
Custom headers
It's possible to set custom headers that will be sent with all requests sent with the client
use Serps\HttpClient\PhantomJsClient;
// The constructor accepts 1 optional parameter that is the path to the phantomjs binaries (default to 'phantomjs')
$client = new PhantomJsClient();
$client->setCustomHeader('referer', 'https://www.google.com');
// All request will the header 'referer: https://www.google.com' added