From 68a5d7d4dbf4036df6f6489a281b1bb43f1b21c3 Mon Sep 17 00:00:00 2001 From: Jim Wigginton Date: Sat, 23 Jul 2011 15:53:23 +0000 Subject: [PATCH] - add real-time in-line logging capabilities to Net/SFTP.php (useful if you're dumping the output to a file or if you're trying to figure out why a script is timing out or something) git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@173 21d32557-59b3-4da0-833f-c5933fad653e --- phpseclib/Net/SFTP.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 871681f9..03c86a2e 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -71,6 +71,10 @@ define('NET_SFTP_LOG_SIMPLE', NET_SSH2_LOG_SIMPLE); * Returns the message content */ define('NET_SFTP_LOG_COMPLEX', NET_SSH2_LOG_COMPLEX); +/** + * Outputs the message content in real-time. + */ +define('NET_SFTP_LOG_REALTIME', 3); /**#@-*/ /** @@ -1520,10 +1524,17 @@ class Net_SFTP extends Net_SSH2 { $stop = strtok(microtime(), ' ') + strtok(''); if (defined('NET_SFTP_LOGGING')) { - $this->packet_type_log[] = '-> ' . $this->packet_types[$type] . - ' (' . round($stop - $start, 4) . 's)'; - if (NET_SFTP_LOGGING == NET_SFTP_LOG_COMPLEX) { - $this->packet_log[] = $data; + $packet_type = '-> ' . $this->packet_types[$type] . + ' (' . round($stop - $start, 4) . 's)'; + if (NET_SFTP_LOGGING == NET_SFTP_LOG_REALTIME) { + echo $this->_format_log(array($data), array($packet_type)); + flush(); + ob_flush(); + } else { + $this->packet_type_log[] = $packet_type; + if (NET_SFTP_LOGGING == NET_SFTP_LOG_COMPLEX) { + $this->packet_log[] = $data; + } } } @@ -1587,10 +1598,17 @@ class Net_SFTP extends Net_SSH2 { $packet = $this->_string_shift($this->packet_buffer, $length); if (defined('NET_SFTP_LOGGING')) { - $this->packet_type_log[] = '<- ' . $this->packet_types[$this->packet_type] . - ' (' . round($stop - $start, 4) . 's)'; - if (NET_SFTP_LOGGING == NET_SFTP_LOG_COMPLEX) { - $this->packet_log[] = $packet; + $packet_type = '<- ' . $this->packet_types[$this->packet_type] . + ' (' . round($stop - $start, 4) . 's)'; + if (NET_SFTP_LOGGING == NET_SFTP_LOG_REALTIME) { + echo $this->_format_log(array($packet), array($packet_type)); + flush(); + ob_flush(); + } else { + $this->packet_type_log[] = $packet_type; + if (NET_SFTP_LOGGING == NET_SFTP_LOG_COMPLEX) { + $this->packet_log[] = $data; + } } }