Skip to content

cognitus/laravel-phantomjs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Say Thanks!

Laravel PhantomJs Client

Using phantomjs client in laravel

Full 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:

// you can use Facade or app make function to use phantomjs
// ex: app('phantomjs') or \PhantomJs

$request = \PhantomJs::get('http://phantomjs.org/');

$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('http://phantomjs.org/', '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('http://phantomjs.org/', '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)

About

🏏 Use phantom-js in laravel

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 95.6%
  • Shell 4.4%