Digpen 7: Why choose Laravel?
-
Upload
john-blackmore -
Category
Software
-
view
1.858 -
download
0
Transcript of Digpen 7: Why choose Laravel?
Why ChooseLaravel?
"Always start your presentation with a quote"
1@rosstuck
Why Choose Laravel?1. Introduction
2. The Problems of Legacy Code
3. Introducing Laravel
4. Laravel in Action
1. Introduction
Who are you
John?
John Blackmore
4 31 Years Old
4 Married with 2 Children
4 14 Years Experience in Web
4 Technical Architect at Crowdcube
The Architect
What isCrowdcube?
4 Equity Crowdfunding Platform
4 £40m Invested, 90k Investors, 150 Pitches
4 Self funded on our own platform, three times.
2. The Problems of Legacy Code
Legacy Code Problems
4 Spaghetti code
4 Limited code re-use
4 Multiple code styles
4 Security vulnerabilities
The Solution?
Our Solution at Crowdcube
4 Develop new features on a framework
4 Agreed coding style (modified PSR-2)
4 Best practises (SoC, DRY, SOLID)
4 Git with Git-Flow
What is a Framework?
Frameworkan essential supporting structure of
a building, vehicle, or object.
a basic structure underlying a system, concept, or text
Software Frameworkan abstraction in which software providing generic
functionality can be selectively changed by additional user-written code, thus providing application-specific software
say what?
A software framework is 80% of your application already written for you.
Why use a framework?
4 Enables rapid development
4 Stable and well tested
4 Community support
4 Easy to recruit developers
Hey, I could buildmy own framework?
Bad IdeaIn most cases
Why you should not build your own
4 You don't have time
4 There will be bugs
4 Difficult to recruit developers
4 Why reinvent the wheel?
Framework Options
3. Introducing Laravel
Laravel Features4 MVC Framework
4 Convention over Configuration
4 Coded to Interfaces:
4 Authentication, Databases, Caching, Queueing
4 Blade templating engine
Why Crowdcube Chose Laravel4 Low learning curve
4 Well documented
4 Excellent test coverage
4 Large active community
4 Built on Symfony components
You can use Laravel features right now
Standalone Components4 Illuminate - https://github.com/illuminate
4 Can be used within non-laravel projects
4 Crowdcube actively uses:
4 illuminate/database
4 illuminate/events
4 illuminate/queue
4. Laravel in ActionExamples from Crowdcube
Legacy Crowdcube Platform4 Single LAMP server
4 Procedural PHP4 code
4 Tightly coupled to MySQL
4 No caching
Where do you start?
ProblemServer load was extremely peaky
Cause: serving static assets from the application server
Solution: Amazon Cloudfront CDN
4 Cloudfront sits in front of existing server
http://www.crowdcube.com/images/some_image.jpghttp://cdn.crowdcube.com/images/some_image.jpg
4 80% reduction in CPU usage
ProblemExisting Database Schema
Solution: Eloquent Models
4 Eloquent maps database tables to PHP models
class Pitches extends Eloquent {}Pitches::whereTitle('Crowdcube'); // returns Crowdcube pitch
4 CRUD operations now simplified in code$user = User::create(['name'=>'John', 'email'=>'[email protected]']);$user->save(); // This can trigger additional events
INSERT INTO `users` (name, email) VALUES ('John', '[email protected]');
ProblemTalking between legacy code
and Laravel code
Solution: Eventing and Worker Queues
4 Amazon SQS Queues
4 Events fired in legacy code
Event::fire('pitch.funded', ['pitch'=>'1234']);
4 Events captured, jobs queued
Queue::push('SendFundedEmail', ['pitch' => '1234'])
4 Queues processed in Laravel
ProblemVisible lag on some pages
e.g. home page, search
Cause: Slow SQL queries
Solution: Query Caching$activePitches = Cache::remember('pitches.active', 10, function(){ return Pitches::active()->get();});
4 Supports APC, Memcached, Redis out the box
4 Typical search query ~400ms from MySQL
4 Same query using file driver <10ms
ProblemNot enough time to talk about
all the really cool stuff
Other Cool Stuff4 Query Scoping
4 View Composers
4 Model Binding
4 Artisan CLI
4 Homestead / Forge
Laravel Resources4 Official Docs - http://laravel.com/docs
4 Laracasts - https://laracasts.com
4 Code Bright - https://leanpub.com/codebright
4 Culttt (Philip Brown) - http://culttt.com
Unless someone like you cares a whole awful lot, Nothing is going to get
better. It’s not.1
The Lorax
Questions?