There was such a problem. I wrote a server-client application with data transfer via a 2-way websockets connection. It works like this. I run the php file from the console, then I update the html page and the connection is established. But. As soon as I try to reload the page, the connection crashes and I need to restart the php file with websockets. Is it possible to make this process run on the server (Apache) automatically, and when reloading the page, reinstall the connection without manual restart?

Thank you in advance!

  • Apparently at first the script weighs in the client's standby mode, then communicates with it. And after the connection is completed, the script also ends. Also, without a code, we will not help. - lampa
  • The fact of the matter is that it did not finish as it should. But now sort of figured out. Anyway, thanks for the replies! - luxor
  • Under Apache, there is no True FastCGI solution. If you decide to write something of your own, then php-fpm (Nginx) will help you, but not [mod_php] [1]. There are many ready-made demons: NodeJS (JS), [PhpDaemon] [2] (PHP), [dklab_realplexor] [3] (PHP) - only Long Polling, Tornado (Python) ... [1]: dklab.ru/ chicken / nablas / 49.html [2]: github.com/kakserpom/phpdaemon/wiki/… [3]: dklab.ru/lib/dklab_realplexor - romeo

2 answers 2

You can solve the problem by running the daemon on a server. If the server is on Linux, then you just need to connect via ssh and run your script or through cli.

If you do not want to suffer with the config, then here is an example of how I run it on a centos:

nohup /usr/bin/php -f <тут путь к серверу> 

    I may not say a topic, but I strongly advise you to use nodejs for this. You will be much more comfortable. Installation will take a couple of minutes. And it's very easy to write a server.

    • one
      Yes, I would not say. First, you propose that the CU switch to another language, and secondly, it is not true about a couple of minutes. - lampa
    • In fact, I was a little hurried. The reason was apparently in a while loop that spun on the server. - luxor
    • one
      About the new language - not a problem. And js and java I know. But about a couple of minutes, yes, usually with the new technology you still have to tinker at first, unless, of course, you just copy-paste from somewhere. But then you will not set it right. - luxor
    • @luxor if you know java - then why php for this purpose? tomcat has ws out of the box. everything is ready, proven. works stably, I recommend. - Vadim