Skip to content

Commit 22cf92a

Browse files
authored
Merge pull request #6 from hemio-ev/PHP-7.0
Adds PHP 7.0 Support
2 parents 71296cd + bf41a39 commit 22cf92a

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,68 @@
11
php-systemd
2-
============
2+
===========
33

44
PHP extension allowing native interaction with systemd and journald
55

66
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
820

9-
sudo yum install -y php-devel systemd-devel
1021
phpize
1122
./configure --with-systemd
1223
make
24+
25+
### Setup
26+
1327
sudo make install
28+
29+
Fedora
30+
1431
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+
1540
echo "<?php echo sd_journal_send('MESSAGE=hello world');" | php
16-
41+
1742
Usage
18-
=====
43+
-----
1944

2045
Quick example:
2146

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+
```
2653

2754
Notes:
2855

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.
3364

34-
Viewing Output
35-
==============
65+
### Viewing Output
3666

3767
Quick way to view output with all fields as it comes in:
3868

config.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PHP_ARG_WITH(systemd, enable support for systemd,
55
if test "$PHP_SYSTEMD" != "no"; then
66

77
SEARCH_PATH="/usr /usr/local"
8-
SEARCH_FOR="/include/sd-journal.h"
8+
SEARCH_FOR="/include/systemd/sd-journal.h"
99

1010
SYSTEMD_DIR=
1111

@@ -32,7 +32,7 @@ if test "$PHP_SYSTEMD" != "no"; then
3232

3333
PHP_ADD_INCLUDE($SYSTEMD_DIR/include)
3434

35-
LIBNAME=systemd-journal
35+
LIBNAME=systemd
3636
LIBSYMBOL=sd_journal_sendv
3737

3838
if test "x$PHP_LIBDIR" = "x"; then

systemd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ ZEND_GET_MODULE(systemd)
3030
PHP_FUNCTION(sd_journal_send)
3131
{
3232
struct iovec *iov = NULL;
33-
zval ***args;
33+
zval *args;
3434
int argc, len, i;
3535
char *val;
3636

37-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) != SUCCESS) {
37+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) != SUCCESS) {
3838
return;
3939
}
4040

@@ -46,10 +46,10 @@ PHP_FUNCTION(sd_journal_send)
4646
}
4747

4848
// Iterate through the PHP arguments and fill the iovector.
49-
for (i = 0; i < ZEND_NUM_ARGS() TSRMLS_CC; ++i) {
50-
convert_to_string_ex(args[i]);
51-
val = Z_STRVAL_PP(args[i]);
52-
len = Z_STRLEN_PP(args[i]);
49+
for (i = 0; i < argc; ++i) {
50+
convert_to_string_ex(&args[i]);
51+
val = Z_STRVAL(args[i]);
52+
len = Z_STRLEN(args[i]);
5353
iov[i].iov_base = val;
5454
iov[i].iov_len = len;
5555
}

0 commit comments

Comments
 (0)