Can yii3 run directly in PHP (CLI SAPI + nginx, not php-fpm + nginx) in production environment?


Yii3 no longer depends on php-fpm, very good direction

rt, I am very happy that yii3 has adopted this strategy, If PHP is resident in memory, we can do more things and get better performance


In development environment, we can run Yii3 using vendor/bin/yii serve

In production environment, can we do this ?

As of PHP 5.4.0, the CLI SAPI provides a built-in web server, vendor/bin/yii serve handle web requests through the build-in web server

In PHP document, there is a warning

This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network

So we cannot run yii3 using vendor/bin/yii serve for production environment


If don’t want to use php-fpm + nginx architecture, we can use asynchronous framework, like Swoole, Amp, ReactPHP, to get higher performace and extend more PHP usage scenarios, like custom network protocol, write Async TCP / UDP / HTTP / Websocket / HTTP2 Client/Server Side API

Hi @jk2K,

I don’t understand what you mean.
Could you show us the detailed information on this 'strategy change in Yii3`?

1 Like

sorry, I seem to have misunderstood it, I mistakenly think that yii3 can no longer need php-fpm

In production environment, yii3 still need php-fpm and nginx, current vendor/bin/yii serve is based on built-in PHP web server feature

yii3 can officially support swoole ? We need higher performance

I see.

I’m sorry but I don’t have any idea about swoole.

Is there a version of Yii that depends on or requires PHP-FPM?

Is there any reason you can’t use Swoole with Yii 2.0?

The serve command is meant for development only.

Are you running a website with php’s built in server?

I will try to use swoole with Yii 3.0 in higher performance requirements or websocket scenarios

Not running yet. I mistakenly thought that yii3 doesn’t need php-fpm and the production environment can use php directly

currently, the production environment needs to rely on php-fpm, this is somewhat limited and not powerful enough. Background tasks and websites need to be run in two ways

No version of Yii requires php-fpm.
It just needs PHP running on you server and a suitable version

I know that php-fpm is not required, but for performance, our practice is generally use php-fpm + nginx,

I don’t think it’s right to say that Yii 3 removes a dependency that prevented Yii 2.0 from meeting your needs.

I use Yii 2.0 with

  • nginx with php-fpm back-end for web app and rest api
  • nginx and websocket server back-end running in PHP CLI SAPI and implemented with ReactPHP/Ratchet
  • TCP and UDP custom protocol server daemons running in PHP CLI SAPI using ReactPHP
  • daemons running in PHP CLI SAPI making multiplexed event-driven outgoing requests using ReactPHP/Guzzle

The first is standard request-driven PHP but the rest are asynchronous and handle multiple tasks with event-driven multiplexing.

We could have done the same with Swoole instead of react using the same architecture.

I do not believe Yii 2.0 and Yii3 are different in this respect. If Yii3 is not going to be stable soon enough for you then I believe you can choose Yii 2.0 and it will work fine with Swoole.

Iiuc, the critical difference between Swoole and ReactPHP is that Swoole is a C/C++ implementation while ReactPHP is PHP and can use a number of event loops including the built-in stream_select(), which we use.


you are right, I realized that my topic title is not very accurate, I changed my title

At this moment there are some problems with running Yii3 w/o nginx-like server in front of it. I’m working on some core fixes in order to support PSR-7 server like RoadRunner.

1 Like

It is certainly a good idea to use a web server to serve web requests.

1 Like