コード例 #1
0
 public static function notice($text)
 {
     if (!defined('STDERR')) {
         if (!static::$fp) {
             static::$fp = fopen('php://stderr', 'w');
         }
     } else {
         static::$fp = STDERR;
     }
     fwrite(static::$fp, $text);
 }
コード例 #2
0
ファイル: MPD.php プロジェクト: Kolbasyatin/mds
 /**
  * Connect to the MPD server
  *
  * @param string $pass
  * The password for the MPD server
  *
  * @param string $host
  * The host name or IP address of the server
  *
  * @param int $port
  * The port number via which to connect to the server
  *
  * @param int $refresh
  * It is not known what this is supposed to be. It's not referenced in the
  * code below.
  */
 public static function connect($pass = "", $host = "", $port = 6600, $refresh = 0)
 {
     // open the connection to the server
     static::$fp = @fsockopen($host, $port, $errno, $errstr, 30);
     // check to see if we successfully connected
     if (!static::$fp) {
         // no connection
         throw new MPDConnectionFailedException("{$errstr} ({$errno})");
     }
     // we did successfully connect
     // keep reading from the connection while we're getting data
     while (!feof(static::$fp)) {
         // get a line from the stream
         $got = fgets(static::$fp, 1024);
         // is the "MPD Ready" message? If so, leave the loop
         if (strncmp("OK", $got, strlen("OK")) == 0) {
             break;
         }
         // set the response value
         static::$response = "{$got}<br>";
         // is it an "ACK" (error) message? if so, leave the loop
         if (strncmp("ACK", $got, strlen("ACK")) == 0) {
             break;
         }
     }
     // do we have a password to send?
     if ($pass != "") {
         // send the password
         fputs(static::$fp, "password \"{$pass}\"\n");
         //Check Password
         // keep reading while we're getting data from the stream
         while (!feof(static::$fp)) {
             // get a line from the stream
             $got = fgets(static::$fp, 1024);
             // is it the "Login OK" message? if so, leave the loop
             if (strncmp("OK", $got, strlen("OK")) == 0) {
                 break;
             }
             // save the response string
             static::$response = "{$got}<br>";
             // is it an "ACK" (error) message? if so, the login failed
             if (strncmp("ACK", $got, strlen("ACK")) == 0) {
                 throw new MPDLoginFailedException();
             }
         }
     }
 }
コード例 #3
0
ファイル: Logger.php プロジェクト: higherchen/rpc
 public static function reset()
 {
     fclose(static::$fp);
     static::$fp = null;
 }
コード例 #4
0
ファイル: logger.php プロジェクト: WineWorld/joomlatrialcmbg
 /**
  * Writes a line to the log, if the log level is high enough
  *
  * @param int|bool $level   The log level (_AE_LOG_XX constants). Use FALSE to pause logging, TRUE to resume logging
  * @param string   $message The message to write to the log
  */
 public static function WriteLog($level, $message = '')
 {
     // Make sure we have a log name
     if (empty(static::$logName)) {
         static::$logName = static::logName();
     }
     // Check for log name changes
     if (is_null(static::$oldLog)) {
         static::$oldLog = static::$logName;
     } elseif (static::$oldLog != static::$logName) {
         // The log file changed. Close the old log.
         if (is_resource(static::$fp)) {
             @fclose(static::$fp);
         }
         static::$fp = null;
     }
     // Close the log file if the level is set to NULL
     if (is_null($level) && !is_null(static::$fp)) {
         @fclose(static::$fp);
         static::$fp = null;
         return;
     }
     if (empty(static::$site_root) || empty(static::$site_root_untranslated)) {
         static::$site_root_untranslated = AEPlatform::getInstance()->get_site_root();
         static::$site_root = AEUtilFilesystem::TranslateWinPath(static::$site_root_untranslated);
     }
     if (empty(static::$configuredLoglevel) or $level === true) {
         // Load the registry and fetch log level
         $registry = AEFactory::getConfiguration();
         static::$configuredLoglevel = $registry->get('akeeba.basic.log_level');
         static::$configuredLoglevel = static::$configuredLoglevel * 1;
         return;
     }
     if ($level === false) {
         // Pause logging
         static::$configuredLoglevel = false;
         return;
     }
     // Catch paused logging
     if (static::$configuredLoglevel === false) {
         return;
     }
     if (static::$configuredLoglevel >= $level && static::$configuredLoglevel != 0) {
         if (!defined('AKEEBADEBUG')) {
             $message = str_replace(static::$site_root_untranslated, "<root>", $message);
             $message = str_replace(static::$site_root, "<root>", $message);
         }
         $message = str_replace("\n", ' \\n ', $message);
         switch ($level) {
             case _AE_LOG_ERROR:
                 $string = "ERROR   |";
                 break;
             case _AE_LOG_WARNING:
                 $string = "WARNING |";
                 break;
             case _AE_LOG_INFO:
                 $string = "INFO    |";
                 break;
             default:
                 $string = "DEBUG   |";
                 break;
         }
         $string .= @strftime("%y%m%d %H:%M:%S") . "|{$message}\r\n";
         if (is_null(static::$fp)) {
             static::$fp = @fopen(static::$logName, "a");
         }
         if (!(static::$fp === false)) {
             $result = @fwrite(static::$fp, $string);
             if ($result === false) {
                 // Try harder with the file pointer, will ya?
                 static::$fp = @fopen(static::$logName, "a");
                 $result = @fwrite(static::$fp, $string);
             }
         }
     }
 }