walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.03k stars 2.25k forks source link

What the best way to use workerman with yii2? #948

Closed shizzic closed 11 months ago

shizzic commented 11 months ago

Just share your implemination please. I think it may be a big help for many ppl.

joanhey commented 11 months ago

I have an implementation with Adapterman.

image

I can help you and show the code.

PD: I think that I read somewhere, than exist an implementation only for yii2.

shizzic commented 11 months ago

I have an implementation with Adapterman.

image

I can help you and show the code.

PD: I think that I read somewhere, than exist an implementation only for yii2.

Please, share your code)

joanhey commented 11 months ago

The code in the benchmark: https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/PHP/yii2

The important parts: server.php https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/PHP/yii2/server.php

Added the 2 lines:

 $_SERVER['SCRIPT_FILENAME'] = '/app/index.php';
 $_SERVER['SCRIPT_NAME'] = '/index.php';

As yii2, don't created it correctly.

The WorkerTimer is because the bench need to have a Date: header. And I didn't want to touch the initial yii2 app code.

index.php https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/PHP/yii2/app/index.php#L54-L62 image

To run with Workerman, you only need to comment the line 54.

Dockefile https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/PHP/yii2/yii2-workerman.dockerfile image

Here I need to change 1 line in yii2, or stop there always (marked with the arrow) And run it php server.php start.

Remember that Adapterman is only an application server, you need to serve static files with the webserver.

shizzic commented 11 months ago

Thank you!