This topic is locked

UDP/Syslog Debug

2/2/2020 1:53:15 PM
PHPRunner Tips and Tricks
C
ckranich authorDevClub member

Hi,
The option $dDebug = true; in AfterAppInit() event throws (at least in my configuration)

tons of messages...
Therefore I wanted to create a debug opportunity more standalone.
I place the following in AfterAppInit() event



//****************************

//* UDP Debug *

//****************************

// make sure the socket extension is enabled

// C:\xampp\php\php.ini : uncomment ;extension=php_sockets.dll

// this code is globally reachable !!

function send_debug($message, $component = "PHPrunner", $program = "PPD")

{

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

foreach(explode("\n", $message) as $line)

{

$syslog_message = "<71>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;

socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, '127.0.0.1','514');

}

socket_close($sock);

}

//send_debug("Test");


fortunately the code here is global for application.

So further send_debug() calls can be placed in the event handlers
Further requisites:

  • enable socks PHP extension
  • Install a Syslog server (like the Free Kiwi Server)
    Greetings,

    ckranich