微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHANTOMJS PHP:空响应对象

当我尝试在本地保存文件时,响应对象返回null.我想要捕获的页面需要大量加载时间,我需要一个回调才能在所有页面资源完全加载时通知我.我的方法是否正确?

当不尝试在本地保存文件时,返回的响应对象不为空.

这是我的代码

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

所有页面资源何时完成加载?

解决方法

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’);

有关更多信息,请参阅此线程:https://github.com/jonnnnyw/php-phantomjs/issues/86

甚至这个线程:https://github.com/jonnnnyw/php-phantomjs/issues/57

原文地址:https://www.jb51.cc/js/155142.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐