D
D
DYLAN2017-03-13 20:39:53
PHP
DYLAN, 2017-03-13 20:39:53

Running daemons from under the Framework, what should I do?

Hello, I've run into the following problem. For my project, I need to create a PHP daemon that will perform certain operations in the background, but I ran into the following problem. If I call the script from under Bitrix through the admin panel, a process is created ( puu.sh/uvxga/13b12c7570.png) which cannot be reached, it simply ignores the signals that are sent to it either through the admin panel (via the PHP command line or or through the launch of the script), or from under the console under the root (For example, Kill -SIGTERM ID), even the Kill command is not able to kill him. The launched script from the CentOS console, on the contrary, responds well to the signals sent.
PHP daemon code:

<?php 
/** 
* @link 
*/ 
declare(ticks = 1); 

$stop = FALSE; 

/** 
* Функция перехватывающая сигналы 
*/ 
function sig_handler($signo) 
{ 
global $stop; 
switch ($signo) 
{ 
case SIGTERM: 
$stop = TRUE; 
break; 
case SIGUSR1: 
break; 
default: 
// Ловим все остальные сигналы 
} 
} 

// Регистрируем сигналы 
pcntl_signal(SIGTERM, "sig_handler"); 
pcntl_signal(SIGUSR1, "sig_handler"); 

// Форкаем процесс 
$pid = pcntl_fork(); 

echo $pid.PHP_EOL; 
if ($pid == -1) 
{ 
// Ошибка 
die('could not fork'.PHP_EOL); 
} 
else if ($pid) 
{ 
// Родительский процесс, убиваем 
die('die parent process'.PHP_EOL); 
} 
else 
{ 
// Новый процесс, запускаем главный цикл 
while( ! $stop ) 
{ 
sleep(1); 
pcntl_signal_dispatch(); 
// полезная работа 
} 
} 
// Отцепляемся от терминала 
?>

It also fails to launch in this way, the framework is blocked
exec("php -f /home/bitrix/www/bitrix/modules/test.testmodule/admin/start_furnace.php");
It turns out that it’s impossible to launch from under the Framework, but what to do, because I need to run demons from under the site’s admin
panel p.s. I read all the articles about demons on Habré!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DiverUA, 2017-03-13
@DiverUA

Try

exec("php -f /home/bitrix/www/bitrix/modules/test.testmodule/admin/start_furnace.php &");

THOSE. add &
AND, preferably, no output commands
AND no closing tag needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question