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


Trending Topics: