定制 josh/laravel-phantomjs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josh/laravel-phantomjs

最新稳定版本:1.1.6

Composer 安装命令:

composer require josh/laravel-phantomjs

包简介

Use phantom-js in laravel

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version Discord License

Laravel PhantomJs Client

Using php-phantomjs client in laravel

php-phantomjs Documentation

Requirement

Install

Via Composer

$ composer require josh/laravel-phantomjs

Config

Add the following provider to providers part of config/app.php

Josh\Component\PhantomJs\PhantomJsServiceProvider::class

and the following Facade to the aliases part

'PhantomJs' => Josh\Component\PhantomJs\Facade\PhantomJs::class

and then you can run vendor:publish command for generating phantomjs config file

$ php artisan vendor:publish --provider="Josh\Component\PhantomJs\PhantomJsServiceProvider"

Now you can config your phantomjs client in config/phantomjs.php file

Basic Usage

The following illustrates how to make a basic GET request and output the page content:

On Load Finished

// 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();
}

Saving a screen capture to local disk:

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

Outputting a page as 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();
}

License

The MIT License (MIT)

统计信息

  • 总下载量: 22.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 44
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 42
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-08