|
1 | 1 | php-systemd
|
2 |
| -============ |
| 2 | +=========== |
3 | 3 |
|
4 | 4 | PHP extension allowing native interaction with systemd and journald
|
5 | 5 |
|
6 | 6 | Installation
|
7 |
| -============ |
| 7 | +------------ |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +.deb based |
| 12 | + |
| 13 | + sudo apt install php5-dev libsystemd-dev |
| 14 | + |
| 15 | +.rpm based |
| 16 | + |
| 17 | + sudo dnf install php-devel systemd-devel |
| 18 | + |
| 19 | +### Build |
8 | 20 |
|
9 |
| - sudo yum install -y php-devel systemd-devel |
10 | 21 | phpize
|
11 | 22 | ./configure --with-systemd
|
12 | 23 | make
|
| 24 | + |
| 25 | +### Setup |
| 26 | + |
13 | 27 | sudo make install
|
| 28 | + |
| 29 | +Fedora |
| 30 | + |
14 | 31 | echo "extension=systemd.so" | sudo tee /etc/php.d/systemd.ini
|
| 32 | + |
| 33 | +Debian (PHP 5) |
| 34 | + |
| 35 | + echo "extension=systemd.so" | sudo tee /etc/php5/mods-available/systemd.ini |
| 36 | + sudo php5enmod systemd |
| 37 | + |
| 38 | +### Basic Test |
| 39 | + |
15 | 40 | echo "<?php echo sd_journal_send('MESSAGE=hello world');" | php
|
16 |
| - |
| 41 | + |
17 | 42 | Usage
|
18 |
| -===== |
| 43 | +----- |
19 | 44 |
|
20 | 45 | Quick example:
|
21 | 46 |
|
22 |
| - <?php |
23 |
| - sd_journal_send('MESSAGE=Hello world.'); |
24 |
| - sd_journal_send('MESSAGE=Hello, again, world.', 'FIELD2=Greetings!', 'FIELD3=Guten tag.'); |
25 |
| - sd_journal_send('ARBITRARY=anything', 'FIELD3=Greetings!'); |
| 47 | +``` {.php} |
| 48 | +<?php |
| 49 | +sd_journal_send('MESSAGE=Hello world.'); |
| 50 | +// message with priority "3" (warning) and identifier (also called *TAG*) set to "appname" |
| 51 | +sd_journal_send('MESSAGE=Error message','PRIORITY=3', 'SYSLOG_IDENTIFIER=appname');" |
| 52 | +``` |
26 | 53 |
|
27 | 54 | Notes:
|
28 | 55 |
|
29 |
| - * Each argument must be in the form of a KEY=value pair, environmental variable style. |
30 |
| - * Unlike the native C version of journald's sd_journal_send(), printf-style substitution is not supported. Perform any substitution using PHP's sprintf() or similar capabilities first. |
31 |
| - * The base message is usually sent in the form MESSAGE=hello. The MESSAGE field is, however, not required. |
32 |
| - * Invalid arguments result in nothing recorded in the journal. |
| 56 | +- Each argument must be in the form of a KEY=value pair, environmental |
| 57 | + variable style. |
| 58 | +- Unlike the native C version of journald's `sd_journal_send()`, |
| 59 | + printf-style substitution is not supported. Perform any substitution |
| 60 | + using PHP's `sprintf()` or similar capabilities first. |
| 61 | +- The base message is usually sent in the form MESSAGE=hello. The |
| 62 | + MESSAGE field is, however, not required. |
| 63 | +- Invalid arguments result in nothing recorded in the journal. |
33 | 64 |
|
34 |
| -Viewing Output |
35 |
| -============== |
| 65 | +### Viewing Output |
36 | 66 |
|
37 | 67 | Quick way to view output with all fields as it comes in:
|
38 | 68 |
|
|
0 commit comments