]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/tools/console/class_ConsoleTools.php
Continued:
[core.git] / framework / main / classes / tools / console / class_ConsoleTools.php
index f4c48d2f392dc9f7b7831d826b06b13f1ee851ee..1e309d76cea9fdd7db5632c62c04e7651b2ac0d8 100644 (file)
@@ -72,6 +72,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         */
        protected function isProxyUsed () {
                // Do we have cache?
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
                if (!isset($GLOBALS[__METHOD__])) {
                        // Determine it
                        $GLOBALS[__METHOD__] = (
@@ -84,6 +85,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                }
 
                // Return cache
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: isUsed=%d', $GLOBALS[__METHOD__]));
                return $GLOBALS[__METHOD__];
        }
 
@@ -98,6 +100,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         */
        protected function setupProxyTunnel (string $host, int $port, $socketResource) {
                // Validate parameter
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: host=%s,port=%d,socketResource=%s - CALLED!', $host, $port, $socketResource));
                if (empty($host)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "host" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
@@ -127,14 +130,16 @@ class ConsoleTools extends BaseFrameworkSystem {
 
                // Add last new-line
                $proxyTunnel .= self::HTTP_EOL;
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-TOOLS: proxyTunnel=' . $proxyTunnel);
 
                // Write request
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Sending %d bytes to socketResource=%s (proxy tunnel) ...', strlen($proxyTunnel), $socketResource));
                fwrite($socketResource, $proxyTunnel);
 
                // Got response?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: feof(%s)=%d', $socketResource, intval(feof($socketResource))));
                if (feof($socketResource)) {
                        // No response received
+                       //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: response()=%d, feof! - EXIT!', count($response)));
                        return $response;
                }
 
@@ -147,6 +152,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                }
 
                // All fine!
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: respArray()=%d - EXIT!', count($respArray)));
                return $respArray;
        }
 
@@ -235,7 +241,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                        throw new InvalidArgumentException('Parameter "hostname" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif (self::$isQuietResolver !== TRUE) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Host name to resolve is: %s',
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:] Host name to resolve is: %s',
                                __CLASS__,
                                $hostname
                        ));
@@ -270,14 +276,14 @@ class ConsoleTools extends BaseFrameworkSystem {
                        // Quiet?
                        if (self::$isQuietResolver !== TRUE) {
                                // Debug message
-                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Resolved IP address is: %s',
+                               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:] Resolved IP address is: %s',
                                        __CLASS__,
                                        $ipAddress
                                ));
                        }
                } else {
                        // Problem while resolving IP address
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem resolving IP address for host %s. Please check your /etc/hosts file.',
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:] Problem resolving IP address for host %s. Please check your /etc/hosts file.',
                                __CLASS__,
                                $hostname
                        ));
@@ -335,7 +341,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                                        $hostname = $_SERVER['COMPUTERNAME'];
                                } else {
                                        // Could not find our hostname
-                                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] WARNING: Cannot acquire my own host name.',
+                                       self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:] WARNING: Cannot acquire my own host name.',
                                                $toolsInstance->__toString()
                                        ));
                                }
@@ -344,7 +350,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: hostname=%s from _SERVER array', $hostname));
                        } catch (FrameworkException $e) {
                                // Output debug message
-                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] Problem while resolving own IP address: [%s|%s]:%s',
+                               self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:] Problem while resolving own IP address: [%s|%s]:%s',
                                        $toolsInstance->__toString(),
                                        $e->__toString(),
                                        $e->getHexCode(),
@@ -414,6 +420,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         */
        public static function determineExternalAddress () {
                // Get helper instance
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
                $toolsInstance = new ConsoleTools();
 
                // First get a socket
@@ -425,6 +432,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                        $ipAddress = self::resolveIpAddress(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('proxy_host'));
 
                        // Connect to host through proxy connection
+                       //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: ipAddress=%s', $ipAddress));
                        $socketResource = fsockopen($ipAddress, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('proxy_port'), $errorNo, $errorStr, 30);
                } else {
                        // Connect to host directly
@@ -432,9 +440,10 @@ class ConsoleTools extends BaseFrameworkSystem {
                }
 
                // Check if there was an error else
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: socketResource[%s]=%s,errorNo=%d,errorStr=%s', gettype($socketResource), $socketResource, $errorNo, $errorStr));
                if ($errorNo > 0) {
                        // Then throw again
-                       throw new InvalidSocketException(array($toolsInstance, $socketResource, $errorNo, $errorStr), BaseFrameworkSystem::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException([$toolsInstance, $socketResource, $errorNo, $errorStr], BaseFrameworkSystem::EXCEPTION_INVALID_SOCKET);
                }
 
                // Prepare the GET request
@@ -465,6 +474,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                $request .= self::HTTP_EOL;
 
                // Send it to the socket
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: Writing %d bytes to socketResource=%s ...', strlen($request), $socketResource));
                fwrite($socketResource, $request);
 
                // Init IP (this will always be the last line)
@@ -473,11 +483,14 @@ class ConsoleTools extends BaseFrameworkSystem {
                // And read the reply
                while (!feof($socketResource)) {
                        // Get line
+                       //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: feof()=%d', intval(feof($socketResource))));
                        $externalAddress = trim(fgets($socketResource, 128));
 
                        // Detect HTTP response
+                       //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CONSOLE-TOOLS: externalAddress=%s', $externalAddress));
                        if ((substr($externalAddress, 0, 7) == 'HTTP/1.') && (substr($externalAddress, -6, 6) != '200 OK')) {
                                // Stop processing
+                               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('CONSOLE-TOOLS: BREAK!');
                                break;
                        }
                }
@@ -486,7 +499,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                fclose($socketResource);
 
                // Return determined external address
-               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-TOOLS: Resolved external address: ' . $externalAddress);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: externalAddress=%s - EXIT!', $externalAddress));
                return $externalAddress;
        }
 
@@ -499,6 +512,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         */
        public static function analyzeEnvironmentForType () {
                // Default is the console
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
                $type = 'console';
 
                // Now, do we have a request method, or query string set?
@@ -508,6 +522,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                }
 
                // Return it
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: type=%s - EXIT!', $type));
                return $type;
        }
 
@@ -526,6 +541,7 @@ class ConsoleTools extends BaseFrameworkSystem {
         */
        public static function analyzeEnvironmentForClassType () {
                // Default is the console
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CONSOLE-TOOLS: CALLED!');
                $type = 'console';
 
                // Now, do we have a request method, or query string set?
@@ -535,6 +551,7 @@ class ConsoleTools extends BaseFrameworkSystem {
                }
 
                // Return it
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: type=%s - EXIT!', $type));
                return $type;
        }