From: Tim Starling Date: Wed, 18 Nov 2009 06:21:27 +0000 (+0000) Subject: Fixed corruption of long UDP debug log messages by using socket_sendto() instead... X-Git-Tag: 1.31.0-rc.0~38766 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=ca0382f09917aca88ff644de36eb82501d798004;p=lhc%2Fweb%2Fwiklou.git Fixed corruption of long UDP debug log messages by using socket_sendto() instead of fsockopen() with fwrite(). Using fwrite() causes the message to be split up into 8KB async send() calls, and whether they end up in the same UDP packet just depends on timing. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 38acde8d8f..7ef10dbaba 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -638,6 +638,8 @@ Hopefully we will remove this configuration var soon) * (bug 21455) Fixed "Watch this page" checkbox appearing on some special pages even to non-logged in users * (bug 21551) Make Squid reponse limit configurable +* Fixed corruption of long UDP debug log messages by using socket_sendto() + instead of fsockopen() with fwrite(). == API changes in 1.16 == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 85bbabb05d..1b6dc2a02c 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -411,13 +411,18 @@ function wfErrorLog( $text, $file ) { // IPv6 bracketed host $protocol = $m[1]; $host = $m[2]; - $port = $m[3]; + $port = intval( $m[3] ); $prefix = isset( $m[4] ) ? $m[4] : false; + $domain = AF_INET6; } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9.-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) { $protocol = $m[1]; $host = $m[2]; - $port = $m[3]; + if ( !IP::isIPv4( $host ) ) { + $host = gethostbyname( $host ); + } + $port = intval( $m[3] ); $prefix = isset( $m[4] ) ? $m[4] : false; + $domain = AF_INET; } else { throw new MWException( __METHOD__.": Invalid UDP specification" ); } @@ -429,12 +434,12 @@ function wfErrorLog( $text, $file ) { } } - $sock = fsockopen( "$protocol://$host", $port ); + $sock = socket_create( $domain, SOCK_DGRAM, SOL_UDP ); if ( !$sock ) { return; } - fwrite( $sock, $text ); - fclose( $sock ); + socket_sendto( $sock, $text, strlen( $text ), 0, $host, $port ); + socket_close( $sock ); } else { wfSuppressWarnings(); $exists = file_exists( $file );