Chirag
Chirag

Reputation: 577

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 ?

Upvotes: 10

Views: 1453

Answers (2)

Sony Mathew
Sony Mathew

Reputation: 2971

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

Upvotes: 2

Viral Solani
Viral Solani

Reputation: 840

I'm facing the same problem. I've used jonnyw/php-phantomjs in laravel.

User setTimeout function. it works for me. try this.

$request->setOutputFile($file);
$request->setTimeout(10000);

Hope it helps.

Upvotes: 0

Related Questions