20162016
Console Apps:
php artisan forthe:win
Joe Ferguson
Who Am I?
Joe Ferguson
PHP Developer
Engineer @ Aol.
Twitter: @JoePFerguson
Organizer of @MemphisPHP
OSMI Board Member
@NomadPHP Lightning Talks
Passionate about Community
Console Apps?!
Shouldn’t we be doing
this in __________ ?
Symfony Console
http://symfony.com/doc/current/components/console.html
Symfony Console
Artisan Console
Laravel Artisan
https://laravel.com/docs/5.3/artisan
Artisan Commands
Create a new Command
Create a new Command
app/Console/Kernel.php
BasicCommand.php
Signature
Description
Constructor
Handle The Command
Running our Command
Output Some Text
Output Some Text
Output Warning Text
Output Warning Text
Output Error Text
Output Error Text
How do we test the
Command?
BasicCommandTest
BasicCommandTest
Adding Checks
BasicCommandTest
Retrieving Input
Arguments
Arguments
Arguments
Arguments
Multiple Arguments
Multiple Arguments
Options
Options
Options
Options
Options
Prompt User For Input
Prompt User For Input
Prompt User For Input
Ask for Confirmation
Ask for Confirmation
Prompt User For Input
Database Backup
Create
DatabaseBackupCommand
app/Console/Commands
Don’t forget Kernel.php!
app/Console/Commands
Look for our Command
Write our handle()
Write our handle()
But we use RDS!
Command SnapshotRds
Write our __construct()
Write our handle()
Running Our Command
AWS Console
I can do that automatically…
What if you don’t use RDS?
spatie/laravel-backup
AWS S3 File Storage
Configure
S3ExampleCommand
List items in a bucket
List items in a bucket
Get an object by Key
Get an object by Key
Deleting old assets
Deleting old assets
Cache Data From APIs
Configure
CacheApiDataCommand
dms/meetup-api-client
meetupConnect()
handle()
Command Arguments
Default in $signature
We need a way to
persist the API data…
Database to the rescue!
Empty Migration
Event Details
Migration up()
Migration down()
Run Migrations
Create Meetup Model
Process the events
Check the database
Now we can pull events
from our database
Elasticsearch
Progress Bar
Progress Bar
Progress Bar
Table Layout
Table Layout
20 Events is a pretty
small data set
GetAllMeetups*
*not all meetups
GetAllMeetups
Command
A larger meetup group
Update the handle()
Run our command
Check the database
Batch Process Large
Data Sets
Configure
BatchProcessCommand
handle()
BatchProcessCommand
Running meetup:expire
Schedule Our
Commands
artisan schedule:run
Scheduling Commands
app/Console/Kernel.php
Scheduling Commands
Real World Twitter
Demo
Questions?
Joe Ferguson
Twitter: @JoePFerguson
Email: joe@joeferguson.me
Freenode: joepferguson
Contact Info:
https://github.com/svpernova09/ConsoleAppsForTheWin

Console Apps: php artisan forthe:win