PHP code example of luka-dev / headless-task-server-php

1. Go to this page and download the library: Download luka-dev/headless-task-server-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luka-dev / headless-task-server-php example snippets


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()

//From var
$task = new Task('here you can past your js');

//OR

//From file
$task = Task::fromFile('./path/to/file.js');

$options = new Options();

//Set locale for our browser
$options->setLocale('en-US');

//Set proxy for our browser (http or socks5)
$options->setUpstreamProxyUrl('http://username:[email protected]:80');

$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();