Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Toptal.com:
PhalconPHP: A Solution for High-load RESTful APIs
Apr 11, 2017 @ 15:26:37

The Toptal.com blog has a tutorial posted from Andrew Belousoff today sharing what he sees as a solution for high-load RESTful APIs in your application: PhalconPHP.

Suppose you need to create a high-load project based on a PHP MVC framework. You would probably use caching wherever possible. Maybe you would build the project in a single file, or maybe even write your own MVC framework with minimal functionality, or rewrite some parts of another framework. While, yes, this works, it’s a little bit tricky, isn’t it? Fortunately, there is one more solution that makes most of these manipulations unnecessary (save for the cache, perhaps), and this solution is called the PhalconPHP framework.

He starts off the article with a brief introduction to the PhalconPHP framework and some of the recent (2016) benchmarks of its performance against both raw PHP and other smaller, lighter MVC frameworks. With that out of the way he starts in on the creation of a sample project, first pointing out the difference between the "micro" and "full-stack" versions. He chooses the "micro" option for his API and walks you through installation of the framework extension, the directory structure it requires and what the code for the front controller looks like. From there he works up the rest of the code:

  • configuration handling
  • working with the DI container
  • creating the RESTful routes/controllers
  • building models
  • developing some business logic to work with user data

The post ends with a look at performing some testing on the result and mentions the addition of logging and caching functionality. He also points out one of the main disadvantages around using PhalconPHP - that it's an extension and is harder to customize than a PHP-land framework could be.

tagged: phalconphp rest api tutorial introduction framework benchmark

Link: https://www.toptal.com/phalcon/phalcon-php-restful-apis


Trending Topics: