简体   繁体   中英

Running websocket server over php-cli stop php-fpm to responds to nginx

I have a nginx server that serve http contents over port 8080 with php-fpm listening on 9002.

Beside this, i have a websocket server socket (also php) running on port 9090.

But when i start my websocket server in command line

php webSocketServer.php

my webserver on port 8080 stop to respond and stuck with a 504 code. (Time-out Gateway)

I m using php7.2 on mac os

log event :

 127.0.0.1 - - [24/Mar/2018:17:52:58 +0100] "GET /api/users HTTP/1.1" 504 183 "-" "GuzzleHttp/6.2.1 curl/7.54.0 PHP/7.2.3" "-"

i have iso-environement running on debian and both are perfectly working together.

i had run

sudo php-fpm -t 
[25-Mar-2018 16:08:40.993971] DEBUG: pid 2513, fpm_log_open(), line 50: open access log (/usr/local/Cellar/php/7.2.3_2/log/www.access.log)
[25-Mar-2018 16:08:40.994024] NOTICE: pid 2513, fpm_conf_init_main(), line 1743: configuration file /usr/local/etc/php/7.2/php-fpm.conf test is successful

and

sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

they both return successful configuration.

output from error.log with verbosity at debug:

2018/03/26 20:14:20 [debug] 2887#0: timer delta: 1
2018/03/26 20:14:20 [debug] 2887#0: worker cycle
2018/03/26 20:14:20 [debug] 2887#0: kevent timer: 60000, changes: 0
2018/03/26 20:14:20 [debug] 2887#0: kevent events: 1
2018/03/26 20:14:20 [debug] 2887#0: kevent: 5: ft:-2 fl:0025 ff:00000000 d:146988 ud:00007FBF3000E8D1
2018/03/26 20:14:20 [debug] 2887#0: *60 http upstream request: "/index.php?"
2018/03/26 20:14:20 [debug] 2887#0: *60 http upstream dummy handler
2018/03/26 20:14:20 [debug] 2887#0: timer delta: 1
2018/03/26 20:14:20 [debug] 2887#0: worker cycle
2018/03/26 20:14:20 [debug] 2887#0: kevent timer: 59999, changes: 0

how i can reproduce this behavior:

  • nginx and php-fpm are started
  • my web socket server is started in command line (php run.php)
  • i run tests to check connectivity to my web app via http request, no responses (until the next two steps)
  • i run tests to check connectivity to my websocket server , working.
  • i stop my websocket server (before timeout 65 from the http request)
  • php-fpm respond to nginx... and all is working fine

what can i deduct ?

  • my web socket server running over php-cli stop php-fpm to send his response to nginx...

How i collected my data :

  • ngrep -d any port 9002
  • checkings logs and tests results

But i have no idea where the problems come from.

There is no reason in the information you have provided to explain why starting a server on port 9090 would have any impact on another server listening on port 9001. Your description of the problem is also innacurate and misleading. The webserver appears to be unaffected and is still responding. It's php-fpm which is no longer responding.

Assuming that you've not built some hidden dependency into the system you've not told us about, then you should start by looking in your logs , and the output of netstat. Would it have been so hard to test what happened with content served directly from nginx rather than php generated content after starting the websockets server?

It was a misunderstanding of my nginx configuration.

I have centralized all my configurations on the nginx.conf file into the http scope instead of separate file for each configuration in scope server.

The structure was as follows:

tcp
    http
     -- all configurations for server and websocket requests

All my http requests were handled in the scope "http". When my websocket server was launch, classic http requests was not handled until the websocket request was ended.

The new structre is the now following:

tcp
   http
       server php #separate file

       websocket php #separate file

       server spring #separate file

       server express #separate file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM