workerman icon indicating copy to clipboard operation
workerman copied to clipboard

[Feature] Use almost any PHP fw or app with Workerman

Open joanhey opened this issue 1 year ago • 70 comments

Hi Walkor,

I was using a lib internally for more than 2 years, for my legacy apps to run with Workerman v3.5. https://github.com/joanhey/AdapterMan

This week I tested with frameworks, and It's working perfectly, without touch 1 line of code in the fw or app.

We only need an small change to the Front Controller and PHP 8 as minimum.

Tested with:

  • Symfony
  • Laravel
  • Yii2
  • Slim
  • KumbiaPHP
  • ...

Now I'm creating PRs in the Techempower benchmark. https://github.com/TechEmpower/FrameworkBenchmarks/pull/7627 https://github.com/TechEmpower/FrameworkBenchmarks/pull/7626 Later I will push Slim and more fws.

I think that this lib will be useful for more people.

If time permits, I'll try to add documentation and upgrade to Workerman v4

joanhey avatar Oct 17 '22 17:10 joanhey

It looks amazing. I thought it was impossible to finish the work, but you solved it easily. Thank you so much for your efforts. 👍

walkor avatar Oct 18 '22 02:10 walkor

Still fixing small details with the session.

The blog work without any problem. Only the admin area, have small problems with the sessions.

Symfony demo with Workerman, an user authenticated : image

joanhey avatar Oct 20 '22 09:10 joanhey

image image image

joanhey avatar Oct 20 '22 09:10 joanhey

Laravel Orchid admin panel with Workerman, with Laravel the login is working image

Drupal with Workerman, but still fail the login with symfony. image

joanhey avatar Oct 22 '22 09:10 joanhey

Laravel and Symfony login working !!!

joanhey avatar Oct 23 '22 13:10 joanhey

That great ! 👍

walkor avatar Oct 23 '22 14:10 walkor

https://user-images.githubusercontent.com/249085/197398600-388ebce3-ece9-4dfa-ba98-fc4d61805e07.mp4

joanhey avatar Oct 23 '22 14:10 joanhey

Now I'll create a docker with the symfony-demo. In port 8080 with Workerman and in 8081 with php-fpm.

joanhey avatar Oct 23 '22 14:10 joanhey

Symfony initialization 0ms. And half time per request, once loaded the first time.

https://user-images.githubusercontent.com/249085/197398802-fb2bc1e4-ec3d-4a2b-9187-4e40585e5ddc.mp4

joanhey avatar Oct 23 '22 14:10 joanhey

Working with CakePHP too

joanhey avatar Oct 27 '22 21:10 joanhey

The first results from the bench Without touch a line of code and full ORM.

Laravel 8

Fw Plaintext Json Single query Multiple query Updates Fortunes
Laravel 14,799 14,770 9,263 3,247 1,452 8,354
Laravel Roadrunner 482 478 474 375 359 472
Laravel Swoole 38,824 37,439 21,687 3,958 1,588 16,035
Laravel Laravel s 54,617 49,372 23,677 2,917 1,255 16,696
Laravel Workerman 103,004 99,891 46,001 5,828 1,666 27,158
Laravel with Workerman % gain 596.02% 576.31% 396.61% 79.489% 14.738% 225.09%

In 2 days Symfony. The next week: Laravel 9, Lumen 9, Cakephp and Slim.

joanhey avatar Nov 04 '22 17:11 joanhey

Very good. It seems that the performance improvement is significant. 👍

walkor avatar Nov 05 '22 00:11 walkor

Yes, it's very significant. And here the results are bad, for using the very slow Laravel ORM.

The next week, we will see the Slim with raw db and optimized db for workerman.

joanhey avatar Nov 05 '22 00:11 joanhey

I don't know any PHP ORM optimised for persistent apps.

joanhey avatar Nov 05 '22 00:11 joanhey

image

The latency is really good !!

image

And later, we will check the memory used. Kumbiaphp use half the memory using Workerman. We will have better numbers with other fws.

joanhey avatar Nov 06 '22 18:11 joanhey

Symfony 6

700% faster in the Fortunes image

Latency

image

Fw Plaintext Json Single query Multiple query Updates Fortunes
Symfony 38,231 37,557 12,578 10,741 3,420 10,741
Symfony Workerman 210,796 197,059 107,050 13,401 4,062 71,092

https://github.com/joanhey/AdapterMan#performance-bench :)

joanhey avatar Nov 07 '22 00:11 joanhey

With CakePHP we have worst results with Workerman. :( I'll investigate if it's an error or directly a problem with CakePHP

joanhey avatar Nov 08 '22 15:11 joanhey

I think that I found the problem, It's related to Cakephp. Changes passed, and in 7 days we have the new results. https://github.com/TechEmpower/FrameworkBenchmarks/pull/7680

Looking the cakephp bootstrap, it check if is CLI SAPI, and load a cli bootstrap.

joanhey avatar Nov 08 '22 23:11 joanhey

Laravel 9 have the same numbers than version 8.

Lumen 9

Fw Plaintext Json Single query Multiple query Updates Fortunes
Lumen 18,998 18,616 10,791 3,496 1,461 9,223
Lumen Swoole 44,861 43,598 24,255 4,178 1,599 16,854
Lumen Laravel s 93,335 82,745 31,567 3,030 1,282 21,130
Lumen Workerman 185,126 177,667 58,729 5,857 1,662 31,430

Very similar numbers to Laravel.

joanhey avatar Nov 10 '22 20:11 joanhey

Trying now with Codeigniter4

joanhey avatar Nov 11 '22 13:11 joanhey

Performance info

Slim3 vs Slim4 without ORM

Framework JSON 1-query 20-query Fortunes Updates Plaintext
Slim 3 35,588 29,529 12,579 28,211 1,999 36,247
Slim 4 38,305 34,272 12,579 32,634 2,097 35,251

:+1:

Slim with Workerman

Without ORM

Framework JSON 1-query 20-query Fortunes Updates Plaintext
Slim 4 38,305 34,272 12,579 32,634 2,097 35,251
Slim 4 Workerman 129,393 81,889 15,803 73,212 2,456 134,531
Slim 4 Workerman pgsql * 102,926 19,637 92,752 14,875
  • Without ORM and db class optimized for Workerman

joanhey avatar Nov 12 '22 17:11 joanhey

CakePHP still slower. Asking for help in the Cakephp slack.

joanhey avatar Nov 14 '22 13:11 joanhey

I'm updating all fw to php 8.2, in the bencmark.

But Workerman 3.5 have problems with dynamic properties. image And fail in some frameworks.

Can we move it from 3.5 to v4, as another protocol ? So we also could optimize it for php 7.

joanhey avatar Nov 16 '22 19:11 joanhey

In the mean time, you or me can add #[\AllowDynamicProperties] To the Worker class and Connection interface.

joanhey avatar Nov 17 '22 01:11 joanhey

In the mean time, you or me can add #[\AllowDynamicProperties] To the Worker class and Connection interface.

Done

walkor avatar Nov 17 '22 03:11 walkor

Walkor, open a twitter for Workerman (and Webman).

joanhey avatar Nov 17 '22 14:11 joanhey

Hi joanhey, here are the twitter accounts.

https://twitter.com/workermanphp https://twitter.com/webmanphp

walkor avatar Nov 21 '22 06:11 walkor

Lumen v9 600% faster image

joanhey avatar Nov 29 '22 12:11 joanhey

Great 👍

walkor avatar Nov 30 '22 04:11 walkor

When you have a moment, Could we talk in private ? Thank you

joanhey avatar Dec 02 '22 14:12 joanhey