当我尝试在本地保存文件时,响应对象返回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