Skip to content

Eien Server

Eien is Leaf's implementation of a high-speed, high-performance server based on powerful tools like Open Swoole and Swoole. Eien loads your app in memory and shares a state between requests to achieve amazing speeds.

When serving Leaf apps with Eien, you gain additional performance improvements due to Leaf's lightweight and super fast nature.

Note that

Eien runs on Swoole, so you need to have the swoole extension installed.


You can easily install Eien using the Leaf CLI:

leaf install eien

Or with Composer.

composer require leafs/eien


Eien has been configured to rely on some features available in only v3 of Leaf. This means that you can't use Eien with earlier versions of the Leaf framework. Not to worry, if you're on Leaf 2, migrating to Leaf 3 should take less than 10 minutes. You can follow this documentation to help you migrate


Leaf WITHOUT Eien:IMG_0785
Leaf WITH Eien:IMG_5389

From the Benchmarks above, Leaf was 40x faster when used with Eien.

Basic Usage

Eien just like the rest of Leaf 3 was built with developer experience in mind. This means that for basic usage, which for most people will be speeding up their applications and simple http features, you don't need to make any modification to your application after installing Eien. Once Leaf detects Eien, it will automatically setup everything and get your app running faster than anything you've seen.


Eien is still in it's dev phase, we have occasional releases, but Eien has not yet been fully tested in production and we'll need your help with that.

Serving Your Application

You can start your application using the php <filename> command. This command will start Eien which will then load your app. Since Eien loads your application to memory, any changes to your application's files will not be reflected when you refresh your browser so we don't recommend this method. You can think of it as starting your nodejs application with node index.js.

What we really need in this case is to watch your files and restart them when there's any update. For this, we tweaked the leaf serve command from the Leaf CLI a bit. You can use the Leaf serve command to start Eien and watch for any changes.

leaf serve <filename>


Since Eien is tied to Leaf, it means that you can't use it with other frameworks. This is because Leaf is built with a very specific architecture that makes it very fast and efficient. This means that you can't use Eien with other frameworks like Laravel, Symfony, etc.

Another major thing to watch out for is the use of PHP functions for responses. All your headers and cookies need to pass through Leaf directly, otherwise Eien won't be able to handle them right. This means you can't use inbuilt PHP functions like header() or setcookie(). You'll need you use Leaf's response->withHeader() and response->withCookie() functions instead.

Eien Server has loaded