Answer the question
In order to leave comments, you need to log in
Daemon in PHP - how to change parameters from the outside?
Hello. I don’t want to arrange a holivar, I need to write a demon in php
The task is this: there is a long-polling request to the server with parameters, for example array('param1'=>'q1,q2', 'param2'=>'q3'), upon receipt of a response a function is called that parses and writes the result to the database (the query continues to work). It is necessary that this query always work when the parameters are set and wait for them to appear when they are not. At the same time, there is a need to change the parameters from the outside - through the database, files or memcash.
How can I tell the daemon that the parameters have changed and the query needs to be restarted? I tried to understand phpDaemon, but without sensible documentation I couldn't do it.
Answer the question
In order to leave comments, you need to log in
Handle HUP signals and others
stackoverflow.com/questions/7864349/how-do-i-catch-a-kill-or-hup-or-user-abort-signal
How about the “check from time to time if the parameters have changed” approach?
You described everything in a very confusing way, I really did not understand. Vkontaktovsky messenger chtoli parse?
I won’t say how specifically in PHP, but the usual approaches are as follows:
If the parameters are NOT changed often, then they are written to the config file and sent to the daemon UNIX signal, for example sighup:
kill SIGHUP
Демон должен установить обработчик этого сигнала - при получении сигнала перечитывать конфиг.
Если меняются часто, то помимо самого "рабочего" сокета, который ждет этот long-pool запрос, открывают еще один - контрольный сокет (слущающий ru.php.net/manual/en/function.socket-listen.php) на котором ждут появления команд/новых параметров. Он может слушать локальный TCP/UDP порт или UNIX сокет, а то и pipe. Правда тогда появляется проблема, что нужно контролировать сразу 2 сокета - тут уже нужны потоки или select/epool.
Ну и третий вариант - просто периодически опрашивать БД/перечитывать конф-файл, например после окончания long-pool запроса или по sleep() если запросов нет. Но это уже детский сад))
phpDeamon examples, in my opinion a bunch, well, or node.js + socket.io.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question