josh / laravel-phantomjs
此包已被废弃且不再维护。没有建议的替代包。
在 Laravel 中使用 phantom-js
1.1.6
2019-10-30 05:57 UTC
Requires
- php: ^7.2
- josh/php-phantomjs: ^4
- laravel/framework: ^6
Requires (Dev)
- phpunit/phpunit: ^7.0
README
Laravel PhantomJs 客户端
在 Laravel 中使用 php-phantomjs 客户端
要求
安装
通过 Composer
$ composer require josh/laravel-phantomjs
配置
将以下提供者添加到 config/app.php 文件的 providers 部分
Josh\Component\PhantomJs\PhantomJsServiceProvider::class
并将以下 Facade 添加到 aliases 部分
'PhantomJs' => Josh\Component\PhantomJs\Facade\PhantomJs::class
然后你可以运行 vendor:publish 命令来生成 phantomjs 配置文件
$ php artisan vendor:publish --provider="Josh\Component\PhantomJs\PhantomJsServiceProvider"
现在你可以在 config/phantomjs.php
文件中配置你的 phantomjs 客户端
基本用法
以下说明了如何进行基本的 GET 请求并输出页面内容
加载完成后
// Tells the client to wait for all resources before rendering $request = \PhantomJs::get('https://www.google.com/'); \PhantomJs::isLazy()->send($request);
// you can use Facade or app make function to use phantomjs // ex: app('phantomjs') or \PhantomJs $request = \PhantomJs::get('https://www.google.com/'); $response = \PhantomJs::send($request); if($response->getStatus() === 200) { // Dump the requested page content echo $response->getContent(); }
将屏幕截图保存到本地磁盘
$request = \PhantomJs::createImage('https://www.google.com/', 'GET'); $request->setOutputFile(public_path('file.jpg')); $request->setViewportSize(800, 600); $request->setCaptureDimensions(800, 600, 0, 0); $response = \PhantomJs::send($request); if($response->getStatus() === 200) { // Dump the requested page content echo $response->getContent(); }
将页面输出为 PDF
$request = \PhantomJs::createPdf('https://www.google.com/', 'GET'); $request->setOutputFile(public_path('document.pdf')); $request->setFormat('A4'); $request->setOrientation('landscape'); $request->setMargin('1cm'); $response = \PhantomJs::send($request); if($response->getStatus() === 200) { // Dump the requested page content echo $response->getContent(); }
许可协议
MIT 许可协议 (MIT)