ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 375 forks source link

Socket get disconnect after certain period of time. #60

Closed vinita90 closed 8 years ago

vinita90 commented 8 years ago

Hi, Now i am working with the major socket based project where i have used this code. No doubt it working extremely good. But there is one problem that is i am starting socket from terminal that is from local, so that it get disconnected if my pc gets down or internet connection get lost. What i want to do is, that i want open socket connection permanently i mean if anybody hit that url than socket should get started. There should be no need to start it first from my terminal. Can i do it in any way.?

currently i am stating my socket like -

canopus@canopus-K54C:~$ ssh root@MY-IP root@MY-IP's password: Last login: Mon Dec 7 14:28:26 2015 from static-3254654654.SP.com root@SERVER-PATH root@server.MY-DOMAIN.com [PHP-Websockets-master]# php -q FILE-NAME.php Server started Listening on: MY-IP:9000 Master socket: Resource id #6

Xaraknid commented 8 years ago

First welcome to Linux.

To keep it simple every app that you start from terminal are link to it. So when the terminal connection a signal is sent "hangup" to every app that you start and will be close.

What you need is to unlink the app from terminal. You can do it by using "nohup". By default every output will be redirect to "nohup.out". To redirect them you can use > redirect.file or simply redirect everything to void by using "> /dev/null 2>&1" not recommended because good luck finding why a crash happens.

so your command

php -q FILE-NAME.php

will look like

nohup php -q FILE-NAME.php > ws.log

Also note that now to close the server you will need to kill it manually.

vinita90 commented 8 years ago

Hey Xaraknid, Thank You. It is working. BTW how will i disconnect socket manually.

Xaraknid commented 8 years ago

Personnaly I use "htop" it's like task manager processes tab under windows. Replace "end process" by "kill" key F9 to close the application.

vinita90 commented 8 years ago

what should be my command. actually i am not getting.

Xaraknid commented 8 years ago

htop is a program you'll need to install if not allready on your system otherwise if you want to do it by command line instead : http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/

vinita90 commented 8 years ago

That is how htop looking but still socket connection is on. htop

vinita90 commented 8 years ago

Xaraknid thanks. My problem resolved.