Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up websockets without command line

How can I follow a tutorial like this without using the command line?

http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/

I need to be able to use websockets but have a shared server and no access to the command line.

I cannot simply run the script from a browser, if the script would stop running when i closed the browser/disconnected from the internet.

like image 214
Max Hudson Avatar asked Feb 15 '13 05:02

Max Hudson


People also ask

How do I setup a WebSocket?

- In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select WebSocket Protocol. Click OK. Click Close.

Does WebSocket require Web server?

By definition websockets like normal sockets are client-server so yes, you need a server. However there is an alternative to waiting for Apache plugins. I am using a hosted server http://www.achex.ca. Its free and you have tutorials in javascript on how to use the server.

What are alternatives to WebSockets?

WebTransport is a new specification offering an alternative to WebSockets. For applications that need low-latency, event-driven communication between endpoints, WebSockets has been the go-to choice, but WebTransport may change that.


2 Answers

Assuming your shared hosting provider supports crontab and cron jobs (most of them do), add the following job to the crontab:

@reboot nohup php /path/to/server.php 2>&1 >/dev/null &

Additionally, you need to start it now, so simply create the following PHP file and access it once, in your browser:

<?php shell_exec('nohup php /path/to/server.php 2>&1 > /dev/null &');?>

That should do the trick. Hopefully your shared hosting provider allows execve() calls to be made. Good luck!

like image 101
Octav O Avatar answered Sep 21 '22 14:09

Octav O


Well try run Server.php on browser. Most of the time a php-cli-script also works fine on browser (Until using some command-line only functionality like argv/argc etc. ). On other tab of browser on in another browser you can run usual url like screenshot in given tutorial.

One important thing, Please check socket and other required extensions is enabled or not on your shared server.

like image 41
kuldeep.kamboj Avatar answered Sep 19 '22 14:09

kuldeep.kamboj