Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHANTOMJS PHP : Empty response object

When I try to save the file locally, the response object is returned null .The page I'm trying to capture takes a lot of loading time for which I need a callback to notify me when all page resources are completely loaded. Is my approach correct ?

When not trying to save the file locally the response object returned is not null.

Here's my code:

$client = Client::getInstance();
$client->getEngine()->setPath('path/to/phantomjs');
    $client->isLazy();

    $request  = $client->getMessageFactory()->createPdfRequest('http://google.com');
    $response = $client->getMessageFactory()->createResponse();

    $file = 'path/binfile.pdf';

    $request->setOutputFile($file);

    $client->send($request, $response);

How do I achieve and know when all the page resources are completely loaded ?

like image 997
Chirag Avatar asked Sep 01 '16 08:09

Chirag


1 Answers

The solution for me was to install phantomjs from my package manager (sudo apt-get install phantomjs) and refer the engine to it, rather than to the phantomjs binary downloaded by composer.

$this->client->getEngine()->setPath('/usr/bin/phantomjs');

For more info refer this thread : https://github.com/jonnnnyw/php-phantomjs/issues/86

or even this thread: https://github.com/jonnnnyw/php-phantomjs/issues/57

like image 160
Sony Mathew Avatar answered Nov 14 '22 07:11

Sony Mathew