High performance, full-stack PHP framework delivered as a C extension.

Overview

Phalcon Framework

Discord Build Status Windows Build Code Coverage Codecov

Contributors

Phalcon Backers OpenCollective OpenCollective

4.1 Pull Requests 4.1 Issues

Phalcon is an open source web framework delivered as a C extension for the PHP language providing high performance and lower resource consumption.

A big thank you to our Backers; you rock!

Getting Started

Phalcon is written in Zephir/C with platform independence in mind. As a result, Phalcon is available on Microsoft Windows, GNU/Linux, FreeBSD and MacOS. You can either download a binary package for the system of your choice or build it from source.

NOTE: Phalcon requires the PSR PHP extension to be installed and enabled.

Installation

For detailed installation instructions you can check our installation page in the docs.

Generating API Documentation

Generating new documentation files for docs repository can be done using the script in tests/_ci/generate-api-docs.php. Steps:

  • Clone the phalcon repo
  • Checkout the tag you would like to generate docs for.
  • Run php tests/_ci/generate-api-docs.php
  • The files *.md files in nikos/api/ will contain the documentation
  • For publishing to the Phalcon website this repo is used.

Links

General

Support

Social Media

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

License

Phalcon is open source software licensed under the BSD 3-Clause License.

Copyright © 2011-present, Phalcon Team.

See the LICENSE.txt file for more. Additional licenses of packages that Phalcon uses, is inspired by or has adapted is located in the 3rdparty/licenses directory.

Comments
  • Strange error after migration to Phalcon 3.0.0

    Strange error after migration to Phalcon 3.0.0

    Hello,

    yesterday, I migrated my project to Phalcon 3.0 (from 2.1 version). And everything worked fine, except now I got very "randomly" this error:

    Fatal error: Uncaught Error: Access to undeclared static property: Phalcon\Di::$_default in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php:25 Stack trace:
    #0 [internal function]: Phalcon\Di->__construct()
    #1 C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php(25): Phalcon\Di\FactoryDefault->__construct()
    #2 C:\xampp-php7-0\htdocs\aplikacija\public\index.php(25): include('C:\\xampp-php7-0...')
    #3 {main}
    
    Next Error: Access to undeclared static property: Phalcon\Di::$_default in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php:25 Stack trace:
    #0 [internal function]: Phalcon\Di->__construct()
    #1 C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php(25): Phalcon\Di\FactoryDefault->__construct()
    #2 C:\xampp-php7-0\htdocs\aplikacija\public\index.php(25): include('C:\\xampp-php7-0...')
    #3 {main} thrown in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php on line 25
    

    On line 25 in my services.php file is where I create instance of DI factory class:

    $di = new FactoryDefault();   ( this is line 25 - error line!)
    $di->setShared('config', function () use ($config) {
        return $config;
    });
    

    I work on Windows, Xampp v3.2.2 with PHP 7.0.8 and Phalcon 3.0.

    Can you help me with this?

    Thanks in advance!

    bug status: low 
    opened by vekyapps 170
  • [NFR] Eager loading support of Phalcon\Mvc\Model

    [NFR] Eager loading support of Phalcon\Mvc\Model

    Once we use model, we always define relationships between models.

    In most cases, we need to implement a list view, displaying objects with its foreign key field's value.

    This will cause a N+1 selects problem (http://use-the-index-luke.com/sql/join/nested-loops-join-n1-problem), slowing down the performance.

    So I think it is necessary to implement the eager loading feature of Phalcon\Mvc\Model.

    opened by hilyjiang 79
  • [NFR] Subqueries in PHQL

    [NFR] Subqueries in PHQL

    Subqueries aren't still supported in PHQL. It would be nice to be able to do it instead of using raw sql.

    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    new feature request 
    opened by hugoduraes 70
  • Broken build with PHP 7.1

    Broken build with PHP 7.1

    With 7.1.0beta1

    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c: In function 'zephir_get_called_class':
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:4764:45: error: 'struct _zend_execute_data' has no member named 'called_scope'
      if (EG(current_execute_data)->called_scope) {
                                                 ^
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:4765:61: error: 'struct _zend_execute_data' has no member named 'called_scope'
       zend_string *ret = EG(current_execute_data)->called_scope->name;
                                                                 ^
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:4770:24: error: 'zend_executor_globals {aka struct _zend_executor_globals}' has no member named 'scope'
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c: In function 'zephir_read_property':
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:5069:31: error: 'zend_executor_globals {aka struct _zend_executor_globals}' has no member named 'scope'
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:5070:19: error: 'zend_executor_globals {aka struct _zend_executor_globals}' has no member named 'scope'
    /builddir/build/BUILD/cphalcon-5372ac7972218b10fd9f08027a7718ea10f191b5/build/NTS/phalcon.zep.c:5090:19: error: 'zend_executor_globals {aka struct _zend_executor_globals}' has no member named 'scope'
      EG(scope) = old_scope;
                       ^
    ...
    
    
    bug status: medium 
    opened by remicollet 67
  • [BUG] v1.3.0 ::findFirst() stopped working as a result of a recent commit

    [BUG] v1.3.0 ::findFirst() stopped working as a result of a recent commit

    Hi,

    It looks like last month has been rough on Phalcon branch 1.3.0.

    My code has suddenly stopped working as a result of commit 7e54b69dcd4c32953c2856c8e92bd29781d4664e:

    Column 'id' doesn't belong to any of the selected models (2), when preparing: SELECT [App\User\Account].* FROM [App\User\Account] WHERE [id] = ?0 AND [record_status] = ?1 LIMIT 1
    
    $parameters = [
        'bind' => [
            0 => 114,
            1 => 1
        ],
        'conditions' => '[id] = ?0 AND [record_status] = ?1'
    ];
    $model = App\User\Account::findFirst($parameters);
    

    Thanks!

    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    bug status: medium 
    opened by temuri416 53
  • PHP7 Support

    PHP7 Support

    PHP7 betas should be rolling out next month, so I think at least master should support it for testing purposes.

    In PHP7 etc/standard/php_smart_str.h has been renamed to etc/standard/php_smart_string.h.

    Compilation for master, 2.0.0, and 2.0.x both fail with the following error:

    /tmp/compile_php_phalcon/cphalcon-2.0.x/build/64bits/phalcon.zep.c:184:40: fatal error: ext/standard/php_smart_str.h: No such file or directory #include <ext/standard/php_smart_str.h> ^ compilation terminated. make: *** [phalcon.lo] Error 1

    I don't know C, otherwise would submit a patch. :)

    opened by quantumpacket 51
  • [BUG] Latest build of Phalcon 1.3.0 is crashing PHPEd

    [BUG] Latest build of Phalcon 1.3.0 is crashing PHPEd

    I had not updated 1.3.0 in about 6-7 weeks. Did that just a moment ago and my PHPEd debugger started crashing when breakpoint is triggered.

    I cloned/compiled 1.2.4 - no problem there.

    The message: Fatal error while fetching local variables. Debug session has been terminated.

    The following is being added to /var/log/kern.log:

    kernel: [ 2213.378010] php-fpm[24084]: segfault at 282 ip 00007f87aef644de sp 00007fffbe358110 error 4 in dbg-php-5.5.so[7f87aef4d000+23000]
    

    Also, there's a huge dump file created: /var/crash/_var_web_php_sbin_php-fpm.33.crash.

    I started checking out commits by ID in reverse chronological order and found that problems started with commit ID

    d21bbf9a779dfbb8598ec8608de60b27cf30d927 (12/11/2013 by Andres - Regenerating build [ci skip])
    

    The one before it works fine.

    Please help! :-)

    Thanks!

    opened by temuri416 50
  • [NFR] Voting for your favorite NFR

    [NFR] Voting for your favorite NFR

    There are a lot of great ideas regarding the framework and additional functionality to help developers. Sadly we cannot do everything in one go, so we have been concentrating in bugs mostly and neglecting NFRs. As such, there have been pages and pages of issues as NFRs that never got any attention.

    In an effort to introduce functionality that the community wants mostly, please read the list below (link to the original issue for reference) and vote in the comments by using the number next to each line below. At the end we will gather the top 5-10 (depending on time constraints) and concentrate on those NFRs.

    This issue will be kept open to track the list of NFRs so that we can address them all if possible. If a NFR does not get any support, it does not mean that we will ignore it.

    Thank you

    UPDATE: Voting issue is here: phalcon/cphalcon#14608

    discussion 
    opened by niden 48
  • [BUG ... possibly?] Exceptions cause loss of user session when remote debugging is on.

    [BUG ... possibly?] Exceptions cause loss of user session when remote debugging is on.

    OK, I might be completely wrong here. But, you never know - maybe I stumbled upon some obscure real issue - so here it comes.

    I use PHPEd remote debugger when developing. Every time when my application throws an exception and it is caught by PHPEd, AND I decide to terminate script execution, I lose user session.

    If I let the execution continue, session is preserved.

    Session is not lost when debugger is off and it does not matter if exception is left unhandled.

    I have never seen anything similar in all my years dealing with remote debugging. So, my question is - could it be that Phalcon's session handler "forgets" the session variables when exception is thrown and execution is aborted from within the IDE?

    I am 100% sure that PHPEd does not flush any superglobals - I've been debugging Exceptions for a long time and never experienced anything similar.

    I can reliably reproduce this behaviour, if anyone from development team wants to have a closer look.

    Thanks!

    bug status: medium 
    opened by temuri416 48
  • [2.1.x] Model alias in getter function not accessible

    [2.1.x] Model alias in getter function not accessible

    Example: Defined relation with alias "roles" in Model named "User".

    I defined a getter function named getRoles() where I want to access $this->roles results in error: Undefined property: User::$roles

    The relation:

    /**
     * @HasMany(
     *     "id",
     *     "Model\UserRole",
     *     "userId",
     *     {
     *         "alias": "roles"
     *     }
     * )
     */
    

    The function:

        public function getRoles()
        {
            if ($this->getDirtyState() == self::DIRTY_STATE_PERSISTENT) {
                $roles = array();
                foreach ($this->roles as $role) {
                    $roles[] = $role->getRole();
                }
    
                return $roles;
            }
    
            return $this->_roles;
        }
    
    bug status: low 
    opened by michanismus 47
  • [2.0.0] Drop support of PHP 5.3

    [2.0.0] Drop support of PHP 5.3

    I was looked on last commits (2.0 branch) and saw some tweaks for support of PHP 5.3 (e.g. https://github.com/phalcon/cphalcon/commit/e8f77329620f05359447ff7df81fa4bb30dd03e7 ). But PHP 5.3 now EOL ( http://php.net/archive/2014.php#id2014-08-14-1 ), so maybe it's time to ignore it in 2.0 branch?

    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    opened by m157y 46
  • [BUG]: response->send(), in Phalcon 5.1.3">

    [BUG]: "Response was already sent" exception with $this->response->send(), in Phalcon 5.1.3

    While adapting my websites running Phalcon 3.4 to run with Phalcon 5, I noticed that AJAX doesn't seem to work. Webpages with Volt views are fine.

    Bug description When using $this->response->send() in controllers (needed with $this->response->setJsonContent(), for example), there is an exception "Response was already sent" (Phalcon\Http\Response\Exception) from $response->send() in public/index.php, and output is not emitted.

    To reproduce

    TestController.php:

    class TestController extends Controller
    {
        public function jsonAction()
        {
            $this->view->disable();
            $this->response->setJsonContent(['test' => 'TEST']);
    
            $this->sendResponse();
        }
    
        public function txtAction()
        {
            $this->view->disable();
            $this->response->setContent('This is a test.');
            $this->response->setContentType('text/plain');
    
            $this->sendResponse();
        }
    
        /**
         * Sending a response in different ways, set $strategy variable to try them.
         */
        protected function sendResponse()
        {
            $strategy = 0;  // [0, 1, 2, 3]
            switch ($strategy) {
                case 0:
                    // Should work, according to docs, but doesn't
                    $this->response->send();
                    break;
                case 1:
                    // Works, but undesirable
                    $this->response->send();
                    exit;
                case 2:
                    // Works, but undesirable
                    echo $this->response->getContent();
                    break;
                case 3:
                    // Not sending a response doesn't work
                    break;
                default:
                    throw new \LogicException("Undefined strategy: '$strategy'");
            }
        }
    }
    

    public/index.php:

    $response = $application->handle($_GET['_url']);
    $response->send();   // Phalcon\Http\Response\Exception: Response was already sent
    

    Expected behavior Should emit JSON or plain text.

    Details

    • Phalcon version: 5.1.3
    • PHP Version: 8.1.2
    • Operating System: Ubuntu 22.04 in WSL
    • Installation type: installing via PECL
    • Server: Apache
    bug status: unverified 
    opened by ewaldberkers 2
  • Update Redis.zep

    Update Redis.zep

    add ttl() and pttl() to that developer can get Redis TTL.

    Hello!

    In raising this pull request, I confirm the following:

    • [x] I have read and understood the Contributing Guidelines
    • [x] I have checked that another pull request for this purpose does not exist
    • [x] I wrote some tests for this PR

    Small description of change: add ttl(), pttl() for Redis. Thanks

    opened by zikezhang 3
  • Memcached meta-data error

    Memcached meta-data error

    Discussed in https://github.com/phalcon/cphalcon/discussions/16225

    Originally posted by quasipickle November 24, 2022 I'm not sure if this is a bug or misconfiguration - I'll re-post as a bug if necessary.

    I'm trying to set up a memcached cache for my model meta-data. When I do so, I get this notice:

    PHP Notice: Cannot use a scalar value as an array in phalcon/Mvc/Model/MetaData.zep on line 630 
    in [trimmed for brevity]AlbumController.php:14
    

    And a thrown exception saying The meta-data is invalid or is corrupt from phalcon/Mvc/Model/MetaData.zep:415

    My cache service is set up like this:

    $Container->set("modelsMetadata", function () {
        $serializerFactory = new Phalcon\Storage\SerializerFactory();
        $adapterFactory = new Phalcon\Cache\AdapterFactory($serializerFactory);
        $options = [
            "servers" => [
                0 => [
                    "host" => "127.0.0.1",
                    "port" => 11211,
                    "weight" => 1
                ]
            ],
            "lifetime" => 86400,
            "prefix" => "pl-2022-11-24-0"
        ];
    
        return new Phalcon\Mvc\Model\Metadata\Libmemcached($adapterFactory, $options);
    });
    

    The only thing I have in my models' initialize() is setting up relationships.

    System: PHP: 8.1.12 Ubuntu: 20.04 (in WSL2 in Windows 10) Phalcon: 5.1.1

    Have I misconfigured something or is this a bug?

    bug status: unverified 5.0 
    opened by niden 2
  • [BUG]: Unexpected LEFT JOIN behavior

    [BUG]: Unexpected LEFT JOIN behavior

    Using Phalcon 4, I'm doing some database queries using query builder and PHQL. Both methods have an issue on using LEFT JOIN. Image any relation, ex. customers and addresses. Example queries are:

    $build = new Builder([
        'models' => ['entity' => Customers::class],
        'joins' => [Addresses::class, 'entity.id=address.customer_id', 'address', 'LEFT'],
        'columns' => ['entity.*', 'address.*'],
    ]);
    $result = $builder
        ->getQuery()
        ->execute();
    foreach ($result as $record) {
        // $record->entity
        // $record->address
    }
    

    or

    $phql = "SELECT entity.*, address.*
        FROM " . Customers::class . " entity
        LEFT JOIN " . Addresses::class . " address ON entity.id=address.customer_id";
    $result = $this->modelsManager
        ->createQuery($phql)
        ->execute();
    foreach ($result as $record) {
        // $record->entity
        // $record->address
    }
    

    When there are customers having addresses, all is fine and I get my data. Now imagine, that there is no address for customer. In real SQL world, I would get NULL for address. But Phalcon returns an freshly instantiated object of type Addresses (without any data) instead of NULL. Is there any ORM option that can be set to return NULL for joined relations that return no data?

    bug status: unverified 
    opened by wurst-hans 0
  • [BUG]: Full namespace class not found inside route annotations

    [BUG]: Full namespace class not found inside route annotations

    Describe the bug

    Controller suffix is repeated when full classname is specified.

    Fatal error: Uncaught ReflectionException: Class "App\Controllers\InvoicesControllerController" does not exist

    To Reproduce

    <?php
    
    use App\Controllers\InvoicesController;
    use Phalcon\Mvc\Router\Annotations;
    
    $container['router'] = function () {
        $router = new Annotations(false);
    
        $router->addResource(Invoices::class, '/admin/invoices');
    
        return $router;
    };
    

    Expected behavior No error when specified full namespace class.

    Details

    • Phalcon version: 5.1
    • PHP Version: 8.1
    • Operating System: any
    bug status: unverified 
    opened by Jeckerson 0
  • Saving related entity in Phalcon 5

    Saving related entity in Phalcon 5

    Discussed in https://github.com/phalcon/cphalcon/discussions/16203

    Originally posted by slechtic November 11, 2022 Hi,

    I'm trying to migrate from Phalcon v3 to v5 but I have a problem with updating related entity.

    I have an entity Document and this entity has related entity DocumentHistory.

    On Document entity there is hasMany relationship defined:

    $this->hasMany('id', DocumentHistory::class, 'idDocument', ['alias' => 'documentHistories']);

    DocumentHistory entity has belongsTo relationship:

    $this->belongsTo('idDocument', Document::class, 'id',['alias' => 'document']);

    when I create new DocumentHistory entity and assign existing Document entity, change some values on this entity (Document) and save DocumentHistory entity, only DocumentHistory is saved (created). Document entity is not updated but foreign key is set on DocumentHistory entity correctly. In case when both entities exist it works correctly.

    $documentHistory = new DocumentHistory();
    
    $document = Document::findFirst($id);
    $document->setNumber($number);
    
    $documentHistory->setDocument($document);
    $documentHistory->save();
    

    On DocumentHistory there is a setter:

    public function setDocument(Document $document) {
        $this->document = $document;
    }
    

    This works for Phalcon v3. This will not be supported in v5 or it is a bug? Thank you.

    My environent:

    PHP 8.1. Phalcon 5.1.0. Postgresql 11

    opened by slechtic 5
Releases(v5.1.3)
Owner
The Phalcon PHP Framework
High performance, full-stack PHP framework delivered as a C extension.
The Phalcon PHP Framework
JShrink is a php class that minifies javascript so that it can be delivered to the client quicker

JShrink JShrink is a php class that minifies javascript so that it can be delivered to the client quicker. This code can be used by any product lookin

Tedious Developments 677 Nov 16, 2022
CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework

CleverStyle Framework is simple, scalable, fast and secure full-stack PHP framework. It is free, Open Source and is distributed under Free Public Lice

Nazar Mokrynskyi 150 Apr 12, 2022
High-Performance Long-Living PHP Framework for modern enterprise application development

Documentation · Discord · Telegram · Twitter Spiral Framework is a High-Performance Long-Living Full-Stack framework and group of over sixty PSR-compa

Spiral Scout 1.4k Jan 1, 2023
Biny is a tiny, high-performance PHP framework for web applications

Biny is high performance. Framework comes default with response time of less than 1ms. Stand-alone QPS easily up to 3000.

Tencent 1.7k Dec 9, 2022
High performance HTTP Service Framework for PHP based on Workerman.

webman High performance HTTP Service Framework for PHP based on Workerman. Manual https://www.workerman.net/doc/webman Benchmarks https://www.techempo

walkor 1.3k Jan 2, 2023
🔥High Performance PHP Progressive Framework.

The Core Framework English | 中文 The QueryPHP Application QueryPHP is a modern, high performance PHP progressive framework, to provide a stable and rel

The QueryPHP Framework 306 Dec 14, 2022
Motan - a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services

Motan-PHP Overview Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Weibo R&D Open Source Projects 81 Nov 19, 2022
Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container, http, log and route.

Kit What is it Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container,

null 2 Sep 23, 2022
Flare is a PHP full-stack web framework that is light, fast, flexible, and secure.

Flare framework is a PHP full-stack web framework that is simple ,powerful , fast , flexible, and secure with long-term support.

Flare framework 3 Oct 24, 2022
A Faster Lightweight Full-Stack PHP Framework

A Faster Lightweight Full-Stack PHP Framework 中文版  Docker env Just one command to build all env for the easy-php How to build a PHP framework by ourse

Zhan Shi 769 Dec 8, 2022
CodeIgniter - a PHP full-stack web framework that is light, fast, flexible and secure

CodeIgniter 4 Development What is CodeIgniter? CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More informatio

CodeIgniter 4 web framework 4.5k Jan 4, 2023
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023
This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on Swoole.

This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on Swoole.

Swoole Taiwan 3.9k Jan 8, 2023
PIP is a tiny application framework built for people who use a LAMP stack.

PIP is a tiny application framework built for people who use a LAMP stack. PIP aims to be as simple as possible to set up and use.

Ron Marasigan 244 Dec 30, 2022
🚀 PHP Microservice Full Coroutine Framework

PHP microservice coroutine framework 中文说明 Introduction Swoft is a PHP microservices coroutine framework based on the Swoole extension. Like Go, Swoft

Swoft Cloud 5.5k Dec 28, 2022
Zephir is a compiled high level language aimed to the creation of C-extensions for PHP.

Zephir - is a high level programming language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C c

Zephir Language 3.2k Dec 27, 2022
Fast php framework written in c, built in php extension

Yaf - Yet Another Framework PHP framework written in c and built as a PHP extension. Requirement PHP 7.0+ (master branch)) PHP 5.2+ (php5 branch) Inst

Xinchen Hui 4.5k Dec 28, 2022
Extension for creating and sending emails for the Yii PHP framework.

yii-emailer Extension for creating and sending emails for the Yii PHP framework. Usage Migrate the email_message database table by this command: yiic

Digia 12 Mar 30, 2022