I
I
ilya_compman2012-02-16 12:22:56
PHP
ilya_compman, 2012-02-16 12:22:56

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

5 answer(s)
D
Dmitry T., 2012-02-16
@tyzhnenko

Handle HUP signals and others
stackoverflow.com/questions/7864349/how-do-i-catch-a-kill-or-hup-or-user-abort-signal

S
Sergey Beresnev, 2012-02-16
@sectus

How about the “check from time to time if the parameters have changed” approach?

S
Sergey, 2012-02-17
@seriyPS

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() если запросов нет. Но это уже детский сад))

A
Artem Bondarenko, 2012-02-17
@mr_avi

phpDeamon examples, in my opinion a bunch, well, or node.js + socket.io.

E
egorinsk, 2012-02-17
@egorinsk

> How can I tell the daemon that the parameters have changed and the query needs to be restarted?
The easiest way is for the daemon to listen on the connection and receive commands on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question