Skip to content

Adds PHP 7.0 Support #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,68 @@
php-systemd
============
===========

PHP extension allowing native interaction with systemd and journald

Installation
============
------------

### Prerequisites

.deb based

sudo apt install php5-dev libsystemd-dev

.rpm based

sudo dnf install php-devel systemd-devel

### Build

sudo yum install -y php-devel systemd-devel
phpize
./configure --with-systemd
make

### Setup

sudo make install

Fedora

echo "extension=systemd.so" | sudo tee /etc/php.d/systemd.ini

Debian (PHP 5)

echo "extension=systemd.so" | sudo tee /etc/php5/mods-available/systemd.ini
sudo php5enmod systemd

### Basic Test

echo "<?php echo sd_journal_send('MESSAGE=hello world');" | php

Usage
=====
-----

Quick example:

<?php
sd_journal_send('MESSAGE=Hello world.');
sd_journal_send('MESSAGE=Hello, again, world.', 'FIELD2=Greetings!', 'FIELD3=Guten tag.');
sd_journal_send('ARBITRARY=anything', 'FIELD3=Greetings!');
``` {.php}
<?php
sd_journal_send('MESSAGE=Hello world.');
// message with priority "3" (warning) and identifier (also called *TAG*) set to "appname"
sd_journal_send('MESSAGE=Error message','PRIORITY=3', 'SYSLOG_IDENTIFIER=appname');"
```

Notes:

* Each argument must be in the form of a KEY=value pair, environmental variable style.
* 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.
* The base message is usually sent in the form MESSAGE=hello. The MESSAGE field is, however, not required.
* Invalid arguments result in nothing recorded in the journal.
- Each argument must be in the form of a KEY=value pair, environmental
variable style.
- 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.
- The base message is usually sent in the form MESSAGE=hello. The
MESSAGE field is, however, not required.
- Invalid arguments result in nothing recorded in the journal.

Viewing Output
==============
### Viewing Output

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

Expand Down
4 changes: 2 additions & 2 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PHP_ARG_WITH(systemd, enable support for systemd,
if test "$PHP_SYSTEMD" != "no"; then

SEARCH_PATH="/usr /usr/local"
SEARCH_FOR="/include/sd-journal.h"
SEARCH_FOR="/include/systemd/sd-journal.h"

SYSTEMD_DIR=

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

PHP_ADD_INCLUDE($SYSTEMD_DIR/include)

LIBNAME=systemd-journal
LIBNAME=systemd
LIBSYMBOL=sd_journal_sendv

if test "x$PHP_LIBDIR" = "x"; then
Expand Down
12 changes: 6 additions & 6 deletions systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ ZEND_GET_MODULE(systemd)
PHP_FUNCTION(sd_journal_send)
{
struct iovec *iov = NULL;
zval ***args;
zval *args;
int argc, len, i;
char *val;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) != SUCCESS) {
return;
}

Expand All @@ -46,10 +46,10 @@ PHP_FUNCTION(sd_journal_send)
}

// Iterate through the PHP arguments and fill the iovector.
for (i = 0; i < ZEND_NUM_ARGS() TSRMLS_CC; ++i) {
convert_to_string_ex(args[i]);
val = Z_STRVAL_PP(args[i]);
len = Z_STRLEN_PP(args[i]);
for (i = 0; i < argc; ++i) {
convert_to_string_ex(&args[i]);
val = Z_STRVAL(args[i]);
len = Z_STRLEN(args[i]);
iov[i].iov_base = val;
iov[i].iov_len = len;
}
Expand Down