Phalcon || Aura
or
A comparison of a PHP framework built as an extension and a bunch of decoupled PHP libraries
Ian Littman
About Me
- @iansltx
- Cloudy Hills
- APIs
- PHP
- DevOps (or something)
Apples || Oranges
- Phalcon
- Framework implemented as a PHP extension (IDE stubs)
- Phalcon 1.x - written in C
- Phalcon 2.x - written in Zephir
- Templating, ORM, cache, etc.
- Classes can be used piecemeal but you're loading the entire extension into RAM either way (500k)
- Aura (v2)
- Small, decoupled user-space (5.3+) libraries
- Insane test coverage
- Framework/Kernel available if you want them (5.4+)
- Both are very flexible/suited to either small or large apps
Benchmark Conditions (TBA)
- Vultr 2GB SSD instance in Dallas
- Ubuntu 14.04 x64
- MariaDB
- nginx (mainline) 1.7.1-1-trusty
- PHP 5.5.12-2+deb.sury.org-trusty+1
- Aura.Web_Project @ a5c1459
- Phalcon 2.0.0 @ cb38388
- Phalcon 1.3.2
- Zend Framework 2.3.1
- Zend Framework 1.12.6
Getting nginx and hhvm working...
location ~ \.(hh|php)$ {
root /usr/share/nginx/html/web;
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
\nFatal error: Argument 1 passed to Aura\\Web\\Request\\Accept\\Charset::__construct() must be an instance of Aura\\Web\\Request\\Accept\\Value\\ValueFactory, null given in /usr/share/nginx/html/vendor/aura/web/src/Request/Accept/Charset.php on line 75
Setup
- Phalcon
- Compile, add to loaded extensions
- Can work with Composer; doesn't need it
- Site has install guides for various web servers
- Aura
- Fetch via Composer...or...
- Use without Composer by requiring each lib's autoload.php
Phalcon - DI
-
Class names, objects, closures, array access (a la Pimple)
-
Altering parameters before instantiation
-
Contstructor, setter, property injection
-
Magic method resolution
-
setShared() for singletons, set() for instances
-
Auto-calls setDi() if available on service construction
-
Singleton option: Phalcon\DI::getDefault()
- Internal libs use DI (we've overridden the Request service)
- Interface available
Phalcon - MVC
- Single-module
- Multi-module
- Microframework
- Directory structure doesn't matter...
- ...because we can autoload!
- Register namespaces, classes, directories
- Add non-php extensions
- Events support (AOP FTW)
Phalcon - Routing + Dispatching
- Route groups
- Parameter transformation
- Annotations
- Short syntax
$sessions->addGet('/{session_id:[a-f0-9]+}', 'Session::getSession');
NOTE: The above syntax will always use the router's default namespace. For alternate namespaces, you'll need to use the longer (standard routing) syntax.
Phalcon - Models
- ORM (magic methods everywhere!)
- Higher-level query language (PHQL)
- Phalcon\Mvc\Model\Query
- SELECT c.name FROM Formula\Cars c ORDER BY c.name
- Query builder + extended PDO
- Migrations (requires Phalcon Developer Tools)
Phalcon - Views
- Hierarchical views via Phalcon\Mvc\View (optional)
- views/index.phtml
- views/layouts/controller_name.phtml
- views/controller_name/action_name.phtml
- $this->getContent()
- View helpers (tags for forms, images, etc.)
- Asset inclusion + minification
- Volt templating (probably {{ looks_familiar }} )
- Compiles templates to PHP
Phalcon - More Goodies
- Debugging - print_r() still works! Phalcon exceptions have stack traces!
- A debugger is also provided...but no try-catch blocks are allowed so that doesn't do much good
- Annotations
- Forms, Validation, Sanitization, Escaping
- URL generation
- Queueing via Beanstalk
Aura - Autoload + DI
- Autoloader (333 sloc)
- PSR-4 + some PSR-0 (slashes only; use v1 for full PSR-0)
- Class-to-file
- Prefixes
- DI
- Eager loading (new with params)
- Lazy loading
- Parameter inheritence
- NOTE: Does not autodetect param types
- Setter injection
- Can pass DI container into services, but not preferred
- Also of note: Includer (e.g. for configs)
Aura - Router + Dispatcher
- Router
- REST resource routing schema (overloadable)
- Closure-based route groups w\defaulting
- Caching generated routes
- Closure-based route execution (microframework style)
- Dispatcher
- Functional focus; uses __invoke()
- Recursive __invoke()
- InvokeMethodTrait for named parameters (Reflection!)
Aura - SQL
- Sql - Extended PDO
-
WHERE IN array binding support
- fetch*() for column, all, etc., including query execution
- Query profiler
- SqlQuery - query builder
- Returns a query object that can be fed into a prepared statement executor
- MySQL, Postgres, MS-SQL, SQLite support
- SqlSchema - object-oriented DESCRIBE
- PDO-based
- Supports the same databases SqlQuery does
Aura - Escaping + Views
- Html (helpers + escaping)
- Quick static escape methods
- $h = $escaper->escape()->html;
- $h($someString);
- Tag and form helpers
- HelperLocator for custom helpers
- View
- Partialx + selections (cached partials)
- Integrates with helper manager
- Two-step view (content rendered into layout)
- Also of note: Filter (v1)
Aura - CLI + Web
- CLI
- Command line arguments with defaulting (positional or not)
- Input/output streams
- Exit codes
- Formatter
- Web
- Request + Response objects
- Request object does content-type negotiation!
- Doesn't actually send anything; that's what this is for
Aura - putting it all together
- Cli_Project
- Web_Project
- Microframework-style or full-stack-style
- I/O + DI + Logging...and that's basically it
- Action-Domain-Responder, anyone?
Performance? Sample apps?
Q&A
Phalcon || Aura
By Ian Littman
Phalcon || Aura
- 4,828