2021-01-31

Start a PHP daemon from a web interface

I am coding a simple chat in 100% PHP, that uses WebSocket (with no external library like in this article).

Obviously, this requires a constantly-running PHP script / daemon / event-loop (similar to how Node.JS works), that we start with:

php -q websockets.php

or nohup ..., or with a dedicated Systemd service (started with systemctl start myservice.service), or with service myservice start.

Question: let's say the person who installs this chat software has no access to command-line (or doesn't know about it enough to do it), how can we start the websockets.php daemon directly from a web page, and keep it constantly running?

The admin could click on a button in his admin panel and, through a XHR/AJAX request, this would trigger a server-side code startup.php. What would be necessary in this startup.php, in order to start and keep websockets.php running forever?

I know exec, but is it adapted in this case?

(More precisely, let's say this admin has no command-line/SSH access, and has only been able to upload the code via (S)FTP; then they can only use a web interface to start or stop the chat daemon server)



from Recent Questions - Stack Overflow https://ift.tt/39zjOoZ
https://ift.tt/eA8V8J

No comments:

Post a Comment