High performance PHP framework

A full-stack PHP framework
delivered as a C extension.

Its innovative architecture makes Phalcon the fastest PHP framework ever built. You do not need to know C to use it: the API is plain PHP classes in the Phalcon\ namespace. Prefer no extension at all? The same API ships as pure PHP.

$ pie install phalcon/cphalcon
$ composer require phalcon/phalcon

open source · BSD-3 / MIT · since 2012

Two flavors, one API

Pick the delivery. Keep the code.

Phalcon comes as a compiled C extension (v5) and as a pure PHP package (v6). Both have the same classes and methods, and the team maintains both.

Phalcon v5

Stable · 5.22.1

C extension, written in Zephir

PHP
8.1 - 8.5
Install
pie install phalcon/cphalcon
License
BSD-3-Clause

Pick this when

  • You want the best speed and the lowest memory use per request.
  • You control the server and the PHP extensions that it loads.

Phalcon v6

Release candidate · 6.0.0RC3

Composer package, pure PHP

PHP
8.1+
Install
composer require phalcon/phalcon
License
MIT

Pick this when

  • Your host does not allow custom PHP extensions.
  • You want to step-debug or run static analysis into framework code.

Backed by

Become a sponsor →

Why it is fast

Low overhead, by design.

Phalcon uses less memory and CPU than traditional frameworks, because the framework is already compiled and loaded before the first request arrives.

How a request reaches your code extension: load once ↻ every request
PHP STARTS
server boots
EXTENSION
loaded once
REQUEST
incoming HTTP
COMPILED CLASSES
ready in memory
RESPONSE
emit output

The tradeoff, stated plainly

Phalcon v6 gives up the raw speed of the compiled extension. In return, there is nothing to install or compile: it runs on any host with PHP 8.1+, and every method is readable in your vendor directory.

Real code, not a fake terminal

The same framework, top to bottom.

Everything a full-stack app needs, organized the same way as the docs. Pick a layer. This code runs on v5 and v6.

A whole app in a handful of lines. The Micro application and the DI container are the same primitives that scale up to a full MVC stack.

index.php
use Phalcon\Http\Response;
use Phalcon\Mvc\Micro;

$app = new Micro();

$app->get('/hello/{name}', function ($name) {
    return new Response("Hello, {$name}!");
});

$app->handle($_SERVER['REQUEST_URI']);

Models map to tables, relationships are declarative, and PHQL gives you a database-agnostic query language that compiles to prepared statements.

Invoices.php
use Phalcon\Mvc\Model;

class Invoices extends Model
{
    public function initialize(): void
    {
        $this->belongsTo('customerId', Customers::class, 'id');
    }
}

$rows = Invoices::find([
    'conditions' => 'total > :min:',
    'bind'       => ['min' => 1000],
]);

Volt is a fast, secure templating engine that compiles to plain PHP. Familiar syntax, compiled once.

invoices/index.volt
{% for invoice in invoices %}
  <tr>
    <td>{{ invoice.id }}</td>
    <td>{{ '%.2f'|format(invoice.total) }}</td>
    <td>{{ invoice.customer.name|e }}</td>
  </tr>
{% endfor %}

Explicit, readable routing. The router, dispatcher, events manager and ACL are separate services that you compose as needed.

routes.php
use Phalcon\Mvc\Router;

$router = new Router(false);

$router->addGet('/invoices', [
    'controller' => 'invoices',
    'action'     => 'index',
]);

$router->addPost('/invoices/create', [
    'controller' => 'invoices',
    'action'     => 'create',
]);

Cross-cutting services (logging, caching, config, security) register in the DI container and resolve lazily, once.

services.php
use Phalcon\Di\FactoryDefault;
use Phalcon\Logger\Adapter\Stream;
use Phalcon\Logger\Logger;

$di = new FactoryDefault();

$di->setShared('logger', function () {
    $adapter = new Stream('php://stderr');

    return new Logger('messages', ['main' => $adapter]);
});

Non-profit · community-built

Built by a community, funded by sponsors.

10.8k
GitHub stars

On cphalcon, the C extension.

60
Top contributors

Shown below. Many more people help with code, docs and tests.

2012
Shipping since

Run as a non-profit and funded by sponsors.

Join the community

Phalcon contributors