Code Monkey home page Code Monkey logo

Comments (18)

BeMySlaveDarlin avatar BeMySlaveDarlin commented on May 23, 2024 1

@pigochu, can you provide some dumps of $_SERVER (somewhere in Swoole::onRequest before application handle)? You can freely remove creds, if any touches dump by envs.

from docs.

pigochu avatar pigochu commented on May 23, 2024 1

@samdark
Today I reinstall yiisoft/app , and use your code.
I got error
I promise I have installed psr/http-factory

PHP Fatal error:  Uncaught Yiisoft\Factory\Exceptions\NotFoundException: No definition for Psr\Http\Message\ResponseFactoryInterface in /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php:226
Stack trace:
#0 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(203): Yiisoft\Di\Container->buildPrimitive()
#1 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(155): Yiisoft\Di\Container->buildInternal()
#2 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(89): Yiisoft\Di\Container->build()
#3 /home/pigo/project/yii3test/vendor/yiisoft/yii-web/src/MiddlewareDispatcher.php(44): Yiisoft\Di\Container->get()
#4 /home/pigo/project/yii3test/vendor/yiisoft/factory/src/Definitions/ArrayBuilder.php(37): Yiisoft\Yii\Web\MiddlewareDispatcher->__construct()
#5 /home/pigo/project/yii3test/vendor/yiisoft/factory/src/Definitions/ArrayDefinition.php(73): Yiisoft\Factory\Definitions\ArrayBuilder->build()
#6 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(223): Yiisoft\Factory\Defini in /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php on line 226
Fatal error: Uncaught Yiisoft\Factory\Exceptions\NotFoundException: No definition for Psr\Http\Message\ResponseFactoryInterface in /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php:226
Stack trace:
#0 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(203): Yiisoft\Di\Container->buildPrimitive()
#1 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(155): Yiisoft\Di\Container->buildInternal()
#2 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(89): Yiisoft\Di\Container->build()
#3 /home/pigo/project/yii3test/vendor/yiisoft/yii-web/src/MiddlewareDispatcher.php(44): Yiisoft\Di\Container->get()
#4 /home/pigo/project/yii3test/vendor/yiisoft/factory/src/Definitions/ArrayBuilder.php(37): Yiisoft\Yii\Web\MiddlewareDispatcher->__construct()
#5 /home/pigo/project/yii3test/vendor/yiisoft/factory/src/Definitions/ArrayDefinition.php(73): Yiisoft\Factory\Definitions\ArrayBuilder->build()
#6 /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php(223): Yiisoft\Factory\Defini in /home/pigo/project/yii3test/vendor/yiisoft/di/src/Container.php on line 226

from docs.

samdark avatar samdark commented on May 23, 2024 1

Fresh updates:

from docs.

samdark avatar samdark commented on May 23, 2024

What's the problem? Doesn't https://github.com/yiisoft/docs/blob/master/guide/en/tutorial/using-yii-with-swoole.md work?

from docs.

pigochu avatar pigochu commented on May 23, 2024

Because I am new to Yii3, I still don’t know the whole architecture very well, so I hope to have a relatively simple example to get started and learn quickly

pigo@PIGO-PC(18.04):~/projects/yii3app$ php swoole-server.php 
Assembling config files
PHP Warning:  require(/home/pigo/projects/src/globals.php): failed to open stream: No such file or directory in /home/pigo/projects/yii3app/swoole-server.php on line 17
Warning: require(/home/pigo/projects/src/globals.php): failed to open stream: No such file or directory in /home/pigo/projects/yii3app/swoole-server.php on line 17
PHP Fatal error:  require(): Failed opening required '/home/pigo/projects/src/globals.php' (include_path='.:/usr/share/php') in /home/pigo/projects/yii3app/swoole-server.php on line 17
Fatal error: require(): Failed opening required '/home/pigo/projects/src/globals.php' (include_path='.:/usr/share/php') in /home/pigo/projects/yii3app/swoole-server.php on line 17

========= I remove require globals.php ================

pigo@PIGO-PC(18.04):~/projects/yii3app$ php swoole-server.php 
Assembling config files
PHP Fatal error:  Uncaught Yiisoft\Factory\Exceptions\NotFoundException: No definition for Psr\Http\Message\ResponseFactoryInterface in /home/pigo/projects/yii3app/vendor/yiisoft/di/src/Container.php:232

from docs.

samdark avatar samdark commented on May 23, 2024

globals.php was removed. Remove it from your entry script as well. I've updated the guide. Then please report back. Thanks.

from docs.

pigochu avatar pigochu commented on May 23, 2024

still not work

PHP Fatal error:  Uncaught Yiisoft\Factory\Exceptions\NotFoundException: No definition for Psr\Http\Message\ResponseFactoryInterface in /home/pigo/projects/yii3app/vendor/yiisoft/di/src/Container.php:226
Stack trace:
#0 /home/pigo/projects/yii3app/vendor/yiisoft/di/src/Container.php(203): Yiisoft\Di\Container->buildPrimitive()
yiisoft/app#1 /home/pigo/projects/yii3app/vendor/yiisoft/di/src/Container.php(155): Yiisoft\Di\Container->buildInternal()

I modify some code

$container = new Container(
    require Builder::path('web')
);

to

$container = new Container(
    require Builder::path('web'),
    require Builder::path('providers-web')
);

but got other error.

image

What i care about is

If I want to design a project that will work with php-fpm and swoole in the future
Is it complicated?

from docs.

samdark avatar samdark commented on May 23, 2024

Is it complicated?

Kind of. Entry point is easy part. I'll get back to it and fix the guide. Currently it seems that it's outdated :( But that's not the major issue that is easily fixable. What's more complicated is the "worker serves many requests" model i.e. https://github.com/yiisoft/docs/blob/master/guide/en/tutorial/using-with-event-loop.md. If your app isn't ready for it, you'll should all kinds on complicated issues with stuck state and memory usage. Framework itself is compatible (or at least was compatible last time I've checked).

from docs.

pigochu avatar pigochu commented on May 23, 2024

@BeMySlaveDarlin

My code :

$server->on('request', static function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($serverRequestFactory, $application) {
    var_dump($_SERVER);
    $psr7Request = $serverRequestFactory->createFromSwoole($request);
    $psr7Response = $application->handle($psr7Request);

    $converter = new \Ilex\SwoolePsr7\SwooleResponseConverter($response);
    $converter->send($psr7Response);
    $application->afterEmit($psr7Response);
});

Dump:

array(41) {
  ["LS_COLORS"]=>
  string(1505) "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"
  ["HOSTTYPE"]=>
  string(6) "x86_64"
  ["LESSCLOSE"]=>
  string(23) "/usr/bin/lesspipe %s %s"
  ["LANG"]=>
  string(7) "C.UTF-8"
  ["AMD_ENTRYPOINT"]=>
  string(36) "vs/server/remoteExtensionHostProcess"
  ["WSL_INTEROP"]=>
  string(21) "/run/WSL/1990_interop"
  ["COLORTERM"]=>
  string(9) "truecolor"
  ["WSL_DISTRO_NAME"]=>
  string(12) "Ubuntu-18.04"
  ["USER"]=>
  string(4) "pigo"
  ["PWD"]=>
  string(34) "/home/pigo/projects/yii3app/public"
  ["HOME"]=>
  string(10) "/home/pigo"
  ["VSCODE_GIT_ASKPASS_NODE"]=>
  string(75) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/node"
  ["TERM_PROGRAM"]=>
  string(6) "vscode"
  ["TERM_PROGRAM_VERSION"]=>
  string(6) "1.48.1"
  ["NAME"]=>
  string(7) "PIGO-PC"
  ["XDG_DATA_DIRS"]=>
  string(50) "/usr/local/share:/usr/share:/var/lib/snapd/desktop"
  ["VSCODE_IPC_HOOK_CLI"]=>
  string(57) "/tmp/vscode-ipc-5653e7e0-b40f-4609-a793-d702dd52524e.sock"
  ["VSCODE_GIT_ASKPASS_MAIN"]=>
  string(106) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/extensions/git/dist/askpass-main.js"
  ["SHELL"]=>
  string(9) "/bin/bash"
  ["TERM"]=>
  string(14) "xterm-256color"
  ["VOLTA_HOME"]=>
  string(17) "/home/pigo/.volta"
  ["SHLVL"]=>
  string(1) "3"
  ["VSCODE_GIT_IPC_HANDLE"]=>
  string(31) "/tmp/vscode-git-8c4a7a869d.sock"
  ["PIPE_LOGGING"]=>
  string(4) "true"
  ["LOGNAME"]=>
  string(4) "pigo"
  ["GIT_ASKPASS"]=>
  string(101) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/extensions/git/dist/askpass.sh"
  ["PATH"]=>
  string(1502) "/home/pigo/.volta/bin:/home/pigo/.vscode-server/bin/3dd905126b34dcd4de81fa624eb3a8cbe7485f13/bin:/home/pigo/.volta/bin:/home/pigo/.local/bin:/home/pigo/.volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files/Volta/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Java/jdk-14.0.1/bin:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet/:/mnt/c/Users/pigo.KJUMP/AppData/Local/Volta/bin:/mnt/c/Users/pigo.KJUMP/AppData/Local/Microsoft/WindowsApps:/mnt/c/ProgramData/chocoportable/bin:/mnt/c/Users/pigo.KJUMP/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/pigo.KJUMP/.dotnet/tools:/snap/bin"
  ["WSLENV"]=>
  string(47) "VSCODE_WSL_EXT_LOCATION/up:VSCODE_SERVER_TAR/up"
  ["LESSOPEN"]=>
  string(22) "| /usr/bin/lesspipe %s"
  ["VERBOSE_LOGGING"]=>
  string(4) "true"
  ["OLDPWD"]=>
  string(27) "/home/pigo/projects/yii3app"
  ["_"]=>
  string(12) "/usr/bin/php"
  ["PHP_SELF"]=>
  string(17) "swoole-server.php"
  ["SCRIPT_NAME"]=>
  string(17) "swoole-server.php"
  ["SCRIPT_FILENAME"]=>
  string(17) "swoole-server.php"
  ["PATH_TRANSLATED"]=>
  string(17) "swoole-server.php"
  ["DOCUMENT_ROOT"]=>
  string(0) ""
  ["REQUEST_TIME_FLOAT"]=>
  float(1597974155.4356)
  ["REQUEST_TIME"]=>
  int(1597974155)
  ["argv"]=>
  array(1) {
    [0]=>
    string(17) "swoole-server.php"
  }
  ["argc"]=>
  int(1)
}
PHP Warning:  session_start(): Cannot start session when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 71
Warning: session_start(): Cannot start session when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 71
PHP Warning:  session_id(): Cannot change session id when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 67
Warning: session_id(): Cannot change session id when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 67
PHP Warning:  session_start(): Cannot start session when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 71
Warning: session_start(): Cannot start session when headers already sent in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Session/Session.php on line 71
PHP Notice:  Undefined index: SCRIPT_NAME in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Middleware/SubFolder.php on line 41
Notice: Undefined index: SCRIPT_NAME in /home/pigo/projects/yii3app/vendor/yiisoft/yii-web/src/Middleware/SubFolder.php on line 41
array(41) {
  ["LS_COLORS"]=>
  string(1505) "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"
  ["HOSTTYPE"]=>
  string(6) "x86_64"
  ["LESSCLOSE"]=>
  string(23) "/usr/bin/lesspipe %s %s"
  ["LANG"]=>
  string(7) "C.UTF-8"
  ["AMD_ENTRYPOINT"]=>
  string(36) "vs/server/remoteExtensionHostProcess"
  ["WSL_INTEROP"]=>
  string(21) "/run/WSL/1990_interop"
  ["COLORTERM"]=>
  string(9) "truecolor"
  ["WSL_DISTRO_NAME"]=>
  string(12) "Ubuntu-18.04"
  ["USER"]=>
  string(4) "pigo"
  ["PWD"]=>
  string(34) "/home/pigo/projects/yii3app/public"
  ["HOME"]=>
  string(10) "/home/pigo"
  ["VSCODE_GIT_ASKPASS_NODE"]=>
  string(75) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/node"
  ["TERM_PROGRAM"]=>
  string(6) "vscode"
  ["TERM_PROGRAM_VERSION"]=>
  string(6) "1.48.1"
  ["NAME"]=>
  string(7) "PIGO-PC"
  ["XDG_DATA_DIRS"]=>
  string(50) "/usr/local/share:/usr/share:/var/lib/snapd/desktop"
  ["VSCODE_IPC_HOOK_CLI"]=>
  string(57) "/tmp/vscode-ipc-5653e7e0-b40f-4609-a793-d702dd52524e.sock"
  ["VSCODE_GIT_ASKPASS_MAIN"]=>
  string(106) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/extensions/git/dist/askpass-main.js"
  ["SHELL"]=>
  string(9) "/bin/bash"
  ["TERM"]=>
  string(14) "xterm-256color"
  ["VOLTA_HOME"]=>
  string(17) "/home/pigo/.volta"
  ["SHLVL"]=>
  string(1) "3"
  ["VSCODE_GIT_IPC_HANDLE"]=>
  string(31) "/tmp/vscode-git-8c4a7a869d.sock"
  ["PIPE_LOGGING"]=>
  string(4) "true"
  ["LOGNAME"]=>
  string(4) "pigo"
  ["GIT_ASKPASS"]=>
  string(101) "/home/pigo/.vscode-server/bin/d5e9aa0227e057a60c82568bf31c04730dc15dcd/extensions/git/dist/askpass.sh"
  ["PATH"]=>
  string(1502) "/home/pigo/.volta/bin:/home/pigo/.vscode-server/bin/3dd905126b34dcd4de81fa624eb3a8cbe7485f13/bin:/home/pigo/.volta/bin:/home/pigo/.local/bin:/home/pigo/.volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/iCLS/:/mnt/c/Program Files/Volta/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Java/jdk-14.0.1/bin:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet/:/mnt/c/Users/pigo.KJUMP/AppData/Local/Volta/bin:/mnt/c/Users/pigo.KJUMP/AppData/Local/Microsoft/WindowsApps:/mnt/c/ProgramData/chocoportable/bin:/mnt/c/Users/pigo.KJUMP/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/pigo.KJUMP/.dotnet/tools:/snap/bin"
  ["WSLENV"]=>
  string(47) "VSCODE_WSL_EXT_LOCATION/up:VSCODE_SERVER_TAR/up"
  ["LESSOPEN"]=>
  string(22) "| /usr/bin/lesspipe %s"
  ["VERBOSE_LOGGING"]=>
  string(4) "true"
  ["OLDPWD"]=>
  string(27) "/home/pigo/projects/yii3app"
  ["_"]=>
  string(12) "/usr/bin/php"
  ["PHP_SELF"]=>
  string(17) "swoole-server.php"
  ["SCRIPT_NAME"]=>
  string(17) "swoole-server.php"
  ["SCRIPT_FILENAME"]=>
  string(17) "swoole-server.php"
  ["PATH_TRANSLATED"]=>
  string(17) "swoole-server.php"
  ["DOCUMENT_ROOT"]=>
  string(0) ""
  ["REQUEST_TIME_FLOAT"]=>
  float(1597974155.4356)
  ["REQUEST_TIME"]=>
  int(1597974155)
  ["argv"]=>
  array(1) {
    [0]=>
    string(17) "swoole-server.php"
  }
  ["argc"]=>
  int(1)
}

from docs.

BeMySlaveDarlin avatar BeMySlaveDarlin commented on May 23, 2024

If i got it right, you are running project on windows under WSL?
It can cause probems related to pathes.
@samdark check out SwooleRequest => PsrRequest converter, maybe missed SCRIPT_NAME var in case its empty or slash when DOCUMENT_ROOT empty.

from docs.

pigochu avatar pigochu commented on May 23, 2024

@BeMySlaveDarlin
My project are running on WSL2 .

from docs.

samdark avatar samdark commented on May 23, 2024

Interesting. It complains about SCRIPT_NAME but it's in the dump.

from docs.

BeMySlaveDarlin avatar BeMySlaveDarlin commented on May 23, 2024

The problem is in between two requests. I suppose when app runs in swoole process, yii request isn't populated with some vars from $_REQUEST or $_SERVER
Also, as i see, there is two dumps. Because there comes two requests on each client call: OPTIONS and * (GET, POST etc)

from docs.

samdark avatar samdark commented on May 23, 2024

So the $_SERVER seems to be alright. Likely that's request/response converting library that is failing. @pigochu would you please try another library?

composer remove ilexn/swoole-convent-psr7
composer require imefisto/psr-swoole-native

Then adjust server.php:

<?php
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Yiisoft\Di\Container;
use Yiisoft\Yii\Web\Application;
use Yiisoft\Composer\Config\Builder;
use Imefisto\PsrSwoole\ResponseMerger;
use Imefisto\PsrSwoole\Request as PsrRequest;

ini_set('display_errors', 'stderr');
require 'vendor/autoload.php';

// Don't do it in production, assembling takes it's time
Builder::rebuild();

$container = new Container(require Builder::path('web'));

$application = $container->get(Application::class);

$responseMerger = new ResponseMerger();

$responseFactory = $container->get(ResponseFactoryInterface::class);
$uriFactory = $container->get(UriFactoryInterface::class);
$uploadedFileFactory = $container->get(UploadedFileFactoryInterface::class);
$streamFactory = $container->get(StreamFactoryInterface::class);

$server = new Swoole\HTTP\Server('0.0.0.0', 9501);

$server->on('start', static function (Swoole\Http\Server $server) use ($application) {
    $application->start();
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on('request', static function (Swoole\Http\Request $request, Swoole\Http\Response $response) use (
        $uriFactory,
        $streamFactory,
        $responseFactory,
        $responseMerger,
$application) {
    $psr7Request = new PsrRequest(
        $request,
        $uriFactory,
        $streamFactory,
        $uploadedFileFactory
    );

    $psr7Response = $application->handle($psr7Request);

    $responseMerger->toSwoole(
            $psr7Response,
            $swooleResponse
    )->end();

    $application->afterEmit($psr7Response);
});

$server->on('shutdown', static function (Swoole\Http\Server $server) use ($application) {
    $application->shutdown();
});

$server->start();

from docs.

samdark avatar samdark commented on May 23, 2024

Need to adjust docs for RR2: https://github.com/spiral/roadrunner/releases/tag/v2.0.0

from docs.

samdark avatar samdark commented on May 23, 2024

yiisoft/di#246 (comment)

from docs.

samdark avatar samdark commented on May 23, 2024

In order to have less concurrency issues w/ Swoole cloning should be used:

$server->on(\Swoole\Constant::EVENT_REQUEST, function (Request $request, Response $response) use ($container) {
    try {
        $requestContainer = clone $container;
        $requestContainer->get(Bird::class);
        $requestContainer->get(StateResetter::class)->reset();
        $container = $requestContainer;
        $response->end('hi');
    } catch (Throwable $t) {
        $response->end($t->getMessage());
    }
});

from docs.

samdark avatar samdark commented on May 23, 2024

Updated docs.

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.