error('Environment variable not found: \''.$variable.'\''); return null; } return self::$_env[$variable]; } /** * Retrieve the IP address of the container. * * @return string|boolean IP address or false */ public function getIpAddress($hostname) { // Request was already done before and is cached if (isset(self::$_ip_address[$hostname])) { return self::$_ip_address[$hostname]; } // New request, generic check $ip = $this->exec('ping -c 1 '.$hostname.'. 2>/dev/null | grep -Eo \'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\' | head -1'); //$ip = gethostbyname($hostname.''); if (filter_var($ip, FILTER_VALIDATE_IP) === false) { //loadClass('Logger')->error('Retrieving the IP address of host \''.$hostname.'\' failed: '.$ip); self::$_ip_address[$hostname] = false; } else { self::$_ip_address[$hostname] = $ip; } return self::$_ip_address[$hostname]; } /** * Shorter version to regex select a string. * * @param string $regex Regex * @param string $string String to look in to * @return bool|string Returns false on error otherwise the string */ public function egrep($regex, $string) { $match = array(); $error = preg_match($regex, $string, $match); if ($error === false) { loadClass('Logger')->error('Error matching regex: \''.$regex. '\' in string: \''.$string.'\''); return false; } return isset($match[0]) ? $match[0] : false; } /** * Executes shell commands on the PHP-FPM Host * * @param string $cmd Command * @param integer $exit_code Reference to exit code * @return string */ public function exec($cmd, &$exit_code = -1) { $output = array(); exec($cmd, $output, $exit_code); return implode ("\n", $output); } }