Awesome
PHP Helper lib for luka-dev/headless-task-server
This lib help to prepare request with your scraper script and parse response.
Install
composer require luka-dev/headless-task-server-php
Usage
- Connect to server
use LuKa\HeadlessTaskServerPhp\Server;
//Let's created connection to specific server
$server = new Server(
'http://127.0.0.1:8080/', //Addres to your task-server
'MySecretAuthKeyIfNeeded' //AUTH_KEY from server
);
//This test will return true, if server work correct
$server->isAlive()
- Create Task
//From var
$task = new Task('here you can past your js');
//OR
//From file
$task = Task::fromFile('./path/to/file.js');
- Set additional Options
$options = new Options();
//Set locale for our browser
$options->setLocale('en-US');
//Set proxy for our browser (http or socks5)
$options->setUpstreamProxyUrl('http://username:password@proxy.com:80');
- Run Task and get Response
$response = $server->runTask($task, $options);
//Get session
$session = $response->getSession();
//Check if Task DONE in correct way
$isDONE = $response->getStatus() === \LuKa\HeadlessTaskServerPhp\Enum\ResponseStatuses::RESOLVE;
//Get Timings (How much time take to process this Task)
$timings = $response->getTimings()
//You can use this:
//$timings->getCreatedAt()
//$timings->getBeginAt()
//$timings->getEndAt()
//Here will be provided all output from `resolve`
$output = $response->getOutput();