2. Who am I?
⢠Barry Jones
⢠Java/Groovy/PHP/Perl developer since â98
⢠Ruby on Rails developer mostly since 2012
⢠Formerly ran Brightball, Inc here in Greenville
â Contract programming business from 2008-2012
â 99% CakePHPâŚ
â Built our platform âThe Intersectâ on top of Cake
⢠Software Architect with ACS Technologies, Inc
6. Before we answer thatâŚ
Why do other languages seem to have clear leaders?
⢠Ruby has Rails
⢠Python has Django
⢠Groovy has Grails
⢠C# has MVC
⢠Java has Spring
7. Many solutions to the same problemâŚ
usually indicates an underlying issueâŚ
which leads to lots of trade offs
8. What does that mean for PHP?
PHP is bad at frameworksâŚ
âŚout of the box
9. So letâs dig into that a little
⢠Ruby, Python, Groovy, C#, and Java have
something in common
⢠They boot upâŚ
â The application gets loaded into RAM
â Runs initializer code
â Makes its database connection(s) with a pool
â Listens for requests and only processes that request
â Can share RAM between requests
â Built for long term garbage collection
10. PHPâŚ
⢠Reprocesses everything on every single request
⢠Configuration
⢠Route mappings
⢠Database connections
⢠Loading all of those framework files
â Devastating to Disk I/O
⢠Encapsulates and garbage collects each individual
process
11. So a PHP framework has tooâŚ
⢠CacheâŚheavily
â And then reload those configuration caches on
every request
⢠Per request RAM allocation is HEAVY
â Itâs not loaded once and then processed
â Framework is loaded every time for every request
13. Rails lit the world on fire
⢠Javaâs Struts popularized MVCâŚbut was awful
⢠Rails made MVC goodâŚ
â And EEEEEEVERYBODY copied it as best they could
â CakePHP was a near clone for a while
â Microsoftâs MVC frameworkâŚalmost carbon copy
â GrailsâŚdo I need to explain this?
14. But why did Rails take off?
⢠Ruby is greatâŚbut itâs not built for the web
⢠PHP is built for the web
⢠Ruby is an excellent language for writing Domain Specific Languages (DSLs)
â ThinkâŚ.
⢠Puppet, Chef, Capistrano, Vagrant
â Rails is a DSL for the web
⢠It changes Ruby to make it a web language
⢠That added to its popularity significantly in the Ruby community
â Nearly every Ruby library has a Rails version for premium integration
â Ruby developers are very big on testing because of the languageâs flexibility
⢠good at testing and easy to break
â Ruby developers place a premium on workflow
⢠Thatâs a heck of a lot more than just arranging some files and throwing
routing and hooks on topâŚthey built an entire mode of operation
15. This is important for PHP
PHP is built for the web out of the box
With no frameworkâŚ
it can rock your face off
16. So why so many frameworks?
⢠WellâŚprior to PHP 5.3
â PHP was terrible for frameworks for all the reasons
previously mentioned
⢠Also, lack of namespaces made sharing libraries a PAAAAIN
â 5.3 was released in 2010
â CakePHP 1.1 was popular in 2006 because it ran on
PHP 4 and PHP 5 while structurally copying Rails
â The PHP âframework warsâ started during a time
when PHP was bad at frameworksâŚhence the variety,
saturation, and trade offs
⢠Everybody tried to solve the problem a different way
17. Prior to 5.3 you needed toâŚ
⢠Enable APC on the server
â Optimized PHP byte code cached in RAM
â Share RAM between process (under Apache mod_php only)
â In production, set APC to not check for file changes
â This got around the Disk I/O and overhead of reloading all those files
â Also drastically reduced per-request RAM
⢠With CakePHP weâd go from 12mb to 2mb (also mod_php only)
⢠Configure a database connection pool within Apache
â OR ensure you were using MySQL because the overhead of new connections is almost
negligible
⢠Avoid .htaccess files like the plague
â Every framework used them for âpretty urlsâ instead of having them added to a server config
⢠Setup a reverse proxy w/ nginx
â Intercept non-application requests prior to Apache processing .htaccess rules
⢠Use framework specific class loaders to try to load things only when necessary
⢠Frameworks had to roll almost everything themselves to avoid naming conflicts
with outside libraries
â Extensive âdoes this work with X?â syndrome
18. So what changed?
⢠In 5.3
â Late static bindings
â Namespaces
⢠In 5.4
â Traits
â Artisan
⢠Built in Web Server
⢠CLI
⢠These allowâŚ
â Lazy loading
â Dependency injection
â Aspect Oriented
Programming (AOP)
â Simpler development
workflow
â Much easier library / package
management
19. What is PHP good at?
⢠Scales down OR up better than any other language
â âBoot upâ web languages canât scale down easily
â With PHP, you can fill up a hard drive with code and it will all work
⢠Other languages, you fill up your RAM and youâre done
⢠This is why PHP shared hosting is everywhere and dirt cheap
⢠Encapsulation of each request provides near perfect server stability
â Tell me next time somebody uses âPHPâ and âMemory Leakâ in a sentence
â If a request dies it canât crash the server
⢠In itâs raw form, it can already do almost everything you need
â Example: Built an on-the-fly image processing server for a huge site
â Same functionality previously kept crashing Rails processes
âŚbecause memory leaks
â Increased efficiency by 3000% (seriously)
21. What is PHP bad at?
More on long polling
⢠PHP is bad at long running process
⢠Long polling involves many long running connections
â which for PHP means many long running processesâŚ
â which will vary based on the number of your users
So for example:
⢠Optimal PHP request/response cycle
â Request received
â PHP started
â Libraries loaded/RAM allocated (2-12mb)
â Request processed
â Request ended, garbage collected
â Total time < .5 seconds (hopefully)
⢠Long polling PHP request/response cycle
â Request received
â PHP started
â Libraries loaded/RAM allocated (2-12mb)
â âŚâŚâŚ. (30-60 seconds)
â Request ended, garbage collected
â Total time 30-60 seconds
â Your servers RAM will be swallowed with a dramatically lower number of users from
holding open dozens of 12mb connections
â You can make it âworkâ but in production youâll have massive scaling issues
from concurrency
⢠nginx_http_push_module â This is not a php specific solution
â Request received with internal response address
â PHP started
â Libraries loaded/RAM allocated (2-12mb)
â Requested added to queue
â Request ended, garbage collected
â Total time < .5 seconds
â nginx holds the long polled connection instead of php
â Single background process pulls requests off the queue and processes them
â Sends response to the internal response address
â The background process handles responding to the long polling request so you control
how many are running in parallel, not your user traffic
â nginx holds the concurrent connections efficiently (as good or greater concurrency than
Node.js)
Long running processes
⢠Please donât use PHP for long
pollingâŚever
⢠No really
⢠All those documents that say PHP
is bad at long pollingâŚdonât take
it as a challengeâŚthey mean it
⢠But if you must use
nginx_http_push_module
AlsoâŚmethod syntax consistency and
assorted other quirksâŚ
22. But itâs more than just code
⢠The business problem:
â How do I find programmers who know this framework?
⢠Case: Brightball
â I loved CakePHP. It was complex, had a steep learning curve but
was incredibly powerful
â We built a tool around it that would generate a permission
controlled, data linked, interface based solely off of the
database structure
⢠AKA âThe Intersectâ (we were big fans of Chuck)
⢠Really bad for billable hours ď
â Hard to find people who knew Cake (or any other specific
framework) despite âpopularityâ numbers
â With complexity, training and learning curve are bad
23. This is where Code Igniter took off
⢠Code Igniter was not as awesome as Cake
(sorry CI people)
â I know one of you wants to argue this pointâŚyour opinion is wrong
⢠But it was a heck of a lot simpler
⢠Learning curve and training ease led to a huge
following
â And Expression Engine
24. Not a problem in other languages
⢠Dominant frameworks lead to common knowledge
bases among developers
⢠Hard to find a Ruby programmer that doesnât know
Rails
⢠That allows continuous evolution because businesses
avoid the training/hiring quandry
⢠Namespaces allows easy library integration and sharing
between frameworks and for the language as a whole
25. Then thereâs workflowâŚ
⢠Common frameworks lead toâŚ
â Common testing integrations
â Common library integrations
â Common database flow
â Common team operations
26. So the answer is�
If I have to tell you the ârightâ framework...
then there isnât a clear choice
31. First the framework wars
⢠What about all the âotherâ frameworks
â All of the existing dominant frameworks have to
maintain a migration path for their user bases
â This makes full reinvention on php >= 5.4âŚhard
⢠Laravel does not have this problem
â But it does need to gain widespread adoption
32. So first upâŚ
Laravel is a Rails clone
And I mean that in a good way
They didnât just go for file structure
Or callbacks
Or active record
Or middleware
Or migrations
Or testing
Or workflow
Or modularity
They ate the wholeâŚdangâŚthing
33. Libraries
Ruby on Rails
⢠Ruby has Gems
⢠Rails applications have a
Gemfile
⢠Bundler installs Gems and
manages dependencies
PHP and Laravel
⢠PHP has Composer
â And PEAR
â And PECL
⢠Laravel uses Composer
⢠Namespaces make this work
34. Dev Environment
Ruby on Rails
⢠Ruby has RVM
â Ruby version manager
â âcdâ into a project directory and
your ruby version and gemset
changes
⢠Bundled web server
â From your project directory, your
application runs
â Dozens of projects in different
versions, with different libraries
and different dependencies are
easy
⢠Command line app access
â Rails console
PHP and Laravel
⢠Php 5.4 + has Artisan
â Going forward, running multiple
local versions of PHP will be easier
â Also will make tools like Foreman
an option for complex apps
⢠Laravel has Homestead
â Complete Vagrant based dev
environment
â A framework that takes dev
environments this seriously is huge
â Will only improve thanks to Docker
⢠Command line app access
â Artisan CLI
35. Migrations
Ruby on Rails
⢠Migrations are âtheâ way
⢠Necessary for teams
working on the same code
locally
⢠Eases deployment across
multiple environments
PHP and Laravel
⢠Migrations are âtheâ way
⢠Virtually identical to Rails
migrations
36. ORM
âLaravel ships with a superb ORM: Eloquent. If
you have used the Ruby on Rails framework, you
will find Eloquent familiar, as it follows the
ActiveRecord ORM style of database
interaction.â
â Laravel documentation
37. Deployment
Ruby on Rails
⢠You can always run your
ownâŚ
⢠But Heroku is where Rails
apps begin
⢠Deployment:
â `git push heroku master`
â Aaaaand thatâs it
PHP and Laravel
⢠You can always run your
ownâŚ
⢠But Laravel Forge makes it
easy to get
ď THAT
On Linode, Digital Ocean,
Rackspace or AWS
38. Other stuff
Ruby on Rails
⢠Built with testing in mind
⢠Queuing is standardized
⢠RESTful
⢠Excellent localization
⢠Extremely well documented
⢠Rack Middleware layer
⢠Highly modular
⢠Very clean syntax
Laravel
⢠Built with testing in mind
⢠Queuing is standardized
⢠RESTful
⢠Excellent localization
⢠Extremely well documented
⢠StackPHP Middleware Layer
⢠Highly modular
⢠Very clean syntax
39. What Laravel needsâŚ
⢠Like any PHP Framework, it needs saturation
⢠Itâs covered all the other bases
â Powerful MVC framework
â Developer workflow
â Full language package management
â Simple, fast deployment options
â Very well documented
â Built for teams (testing + migrations)
â Modular
⢠Just needs more people using it to solve the âhiringâ
case