note 60062 added to function.fsockopen

From: Date: Sat, 24 Dec 2005 13:41:17 +0000
Subject: note 60062 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-100659@lists.php.net to get a copy of this message
We have implemented a Syslog class in PHP following the RFC 3164 rules. Using this class, it is possible to send syslog messages to external servers. We use this class for example to log information, to synchronize some processes or to launch external "threads". Class abstract, full class implementation can be found at http://developer.sysco.ch/php/ <?php // (...) class Syslog { var $_facility; // 0-23 var $_severity; // 0-7 var $_hostname; // no embedded space, no domain name, only a-z A-Z 0-9 and other authorized characters var $_fqdn; var $_ip_from; var $_process; var $_content; var $_msg; var $_server; // Syslog destination server var $_port; // Standard syslog port is 514 var $_timeout; // Timeout of the UDP connection (in seconds) // (...) function Send($server = "", $content = "", $timeout = 0) { // (...) $actualtime = time(); $month = date("M", $actualtime); $day = substr(" ".date("j", $actualtime), -2); $hhmmss = date("H:i:s", $actualtime); $timestamp = $month." ".$day." ".$hhmmss; $pri = "<".($this->_facility*8 + $this->_severity).">"; $header = $timestamp." ".$this->_hostname; // (...) $msg = $this->_process.": ".$this->_fqdn." ".$this->_ip_from." ".$this->_content; $message = substr($pri.$header." ".$msg, 0, 1024); $fp = fsockopen("udp://".$this->_server, $this->_port, $errno, $errstr, $this->_timeout); if ($fp) { fwrite($fp, $message); fclose($fp); $result = $message; } else { $result = "ERROR: $errno - $errstr"; } return $result; } // (...) ?> Example <?php require_once('syslog.php'); $syslog = new Syslog(); $syslog->Send('192.168.0.12', 'My first PHP syslog message'); ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60062 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60062&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60062&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100659) next »