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

Laravel News:
Speed Up Laravel on Top of Swoole
May 07, 2018 @ 15:47:09

On the Laravel News site there's a tutorial posted showing you how to use the Swole extension to speed up your Laravel-based application. Swole is a PHP extension written in C that provides missing asynchronous functionality to the language.

Swoole is a production-grade async programming framework for PHP. It is a PHP extension written in pure C language, which enables PHP developers to write high-performance, scalable, concurrent TCP, UDP, Unix socket, HTTP, WebSocket services in PHP without too much knowledge of the non-blocking I/O programming and low-level Linux kernel. You can think of Swoole as something like NodeJS but for PHP, with higher performance.

The post covers the "why?" question of using Swoole with Laravel, explaining how the traditional PHP request flow works. Swoole provides a way to reduce come of this processing overhead and increase performance. They then help you integrate Swoole and Laravel using a custom package (swooletw/laravel-swoole), installing both the package and using PECL to install the Swoole extension. Once the extension is enabled and the service provider is added, all it takes is an artisan command to start the web server up.

The post finishes with some quick benchmarks using wrk comparing it against a typical Nginx setup with PHP-FPM. Not surprisingly, Swoole outperforms the other setup well.

tagged: laravel swoole extension performance tutorial package install

Link: https://laravel-news.com/laravel-swoole

Zend Framework Blog:
Async Expressive? Try Swoole!
Mar 22, 2018 @ 14:28:22

On the Zend Framework blog there's a new tutorial posted that wants to help you use Expressive for asynchronous request handling with the help of the Swoole extension.

When we were finalizing features for Expressive 3, we had a number of users testing using asynchronous PHP web servers. As a result, we made a number of changes in the last few iterations to ensure that Expressive will work well under these paradigms.

Specifically, we made changes to how response prototypes are injected into services.

The article starts by talking about the issue with the previous response prototype handling, mostly that, in an async world, all responses would be sharing the same instance rather than rebuilding a new one for each request. It then explains their reasoning behind even worrying about async support in the framework's response handling noting that the major reason had to do with the performance gain. The post mentions the Swoole extension and shows how to install it via PECL but you'll need to check out the project's documentation to see how to create a server that makes use of it.

tagged: asynchronous swoole extension zendframework zendexpressive v3

Link: https://framework.zend.com/blog/2018-03-21-expressive-swoole.html

SitePoint PHP Blog:
Can PHP Be Even Faster? Light-Speed with the Blink Framework
Jan 18, 2016 @ 15:20:27

The SitePoint PHP blog has a tutorial posted that looks at a framework that could "make PHP go even faster", the Blink framework.

Blink was built to improve high performance applications that consume a lot of server resources, and it uses the Swoole PHP extension to achieve this goal. As an example, we will build a Blink powered notejam for our demo.

First the tutorial walks you through the installation of the Swoole extension (they choose from PEAR but you can also install from GitHub). Next up they install the Blink framework with a new project and fire up the built-in server to ensure it's working correctly. With that up and running they show how to configure the framework/server and get into building the sample "notejam" application. They make use of Twig for templating the frontend and several Illuminate packages for the database, console and filesystem functionality.

The remainder of the post walks through the actual code for the application:

  • creating and using the "notes" table
  • working with routing
  • creating templates
  • working with user management

Finally, with this system in place they show how to have a user verify themselves and add a new note to their list.

tagged: blink framework fast swoole extension tutorial note application

Link: http://www.sitepoint.com/can-php-be-even-faster-light-speed-with-the-blink-framework/


Trending Topics: