3
  1. We are using AWS EC2(ubuntu-xenial-16.04-amd64-server) instance for running PHP Websocket server.
  2. We are using following command, in order to keep WebSocket server running continuously.

    nohup php -q server.php >/dev/null 2>&1 &

  3. It is running very well up to two days.But if no client has connected to WebSocket server in last two days,it automatically stops responding.

  4. I checked the status of WebSocket port with this command (lsof -i:9000).I got following output(5&6)

  5. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

  6. php 1467 ubuntu 4u IPv4 17137 0t0 TCP *:9000 (LISTEN)

  7. It seems WebSocket server is running.But client(i.e. mobile application) is not able to connect.

    Is there any specific reason behind this problem? We are not able to figure out exact issue.

Dinesh Belkare
  • 639
  • 8
  • 24
  • Have you read the logs? – zed Feb 06 '17 at 19:03
  • may be you exhausted the no. of open files. default is less. See http://unix.stackexchange.com/questions/36841/why-is-number-of-open-files-limited-in-linux – Sairam Feb 07 '17 at 09:07

1 Answers1

1

You'll need to provide more information for SO community to be able to help you.

Let's look at the layers for your infrastructure make an educated guess where the problem might be.

We have:

  • external connector (the mobile app)
  • PHP script acting as a server (receiver).
  • OS (Ubuntu)

OS kernel can kill running processes for various misbehaves. Most common OOM-killer (out-of-memory).

It's not uncommon to see PHP scripts becoming unresponsive especially when stream (sockets) programming is involved, we'll need to see that code.

You are saying that everything is fine for two days, so we can rule out external connector problem and concentrate on mismanaging of resources problems: garbage-collection, memory leaks, stream leaks, etc. Some external process is either killing your PHP script or PHP script itself becomes unresponsive.

The investigation should start at:

  1. Sharing the server.php, and then moving to
  2. Log analysis.
rock3t
  • 2,193
  • 2
  • 19
  • 24