Riz
Riz

Reputation: 7012

Sending signal to daemon in php

I have a daemon written in PHP which is running on my linux machine.

I am trying to send a signal to it through another php file. For this purpose I am trying posix_kill function. But its not working.

When I run the php page, I get an error that php is compiled without --enable-grep

I want to know how to enable it? OR what is the alternate way of sending signal to daemon?

Upvotes: 1

Views: 5155

Answers (3)

Rafa
Rafa

Reputation: 1495

The only way to handle signals on your PHP script is to re-compile PHP with the PCNTL library that will give you the tools/functions you need.

http://php.net/manual/en/book.pcntl.php

Otherwise, you need to use workarounds like Quamis mentioned : file flags or locks, etc.

Upvotes: 1

Quamis
Quamis

Reputation: 11087

Try using shared memory, locks, or files. Sending signals between processes may not work if the process belongs to a different user.

Using files or locks for example may help you if you ever need to scale, as its easier to replicate than using signals.

The problems with signalling like i've said is that the daemon must look periodically for events... by using signals a certain trigger in the daemon would get instantly called, and that makes life easier if you need a fast response back.

Upvotes: 0

Andy
Andy

Reputation: 17791

If you know the process's ID, you could just

exec( "kill -SIGKILL 1234", $return );
print_r( $return );

Or if you don't know the process ID

exec( "pkill -KILL myDaemon", $r );
print_r( $return );

To find all the available signals you could send:

shell> kill -l

If you are having trouble, redirect stderr to standard output:

exec( "pkill -KILL myDaemon 2>&1", $r );
print_r( $return );

This will show you any error messages that would have appeared on the terminal (had you been executing the command that way!).

Upvotes: 0

Related Questions