Details

    • Bug
    • Resolution: Not A Bug
    • Major
    • None
    • CE-22.5
    • Web Interface
    • None
    • Prod

    Description

      We did an upgrade to the latest.

      Ever since, nothing works. can't even get to the login page.

      We have Enterprise license.

      Need immediate support.

      this is the error.

      PHP Fatal error:  str_replace(): Cannot use output buffering in output buffering display handlers in /data/observium/html/includes/functions.inc.php on line 103

      Please let me know asap.
      Thanks.

      Attachments

        Activity

          [OBS-4926] PHP Fatal error: str_replace():

          Observium initially recommend to use minimum 512M php memory for web ui.

          landy Mike Stupalov added a comment - Observium initially recommend to use minimum 512M php memory for web ui.

          I hope the code I posted here helps you.

          you can close the issue.

          thanks.

          steve.r.leroux.rfnow Steve Leroux added a comment - I hope the code I posted here helps you. you can close the issue. thanks.

          php memory - yup.

          not sure if you saw my messages in discord.

          • Discord

          it's a weird one.

          thanks adam.

          steve.r.leroux.rfnow Steve Leroux added a comment - php memory - yup. not sure if you saw my messages in discord. • Discord it's a weird one. thanks adam.

          This is a helpfully cryptic error from PHP, but it's likely that you need to increase the memory limit in php.ini.

          Make sure it's set in the correct php.ini, because there are almost always separate files for CLI and web (and usually separate files for each version of PHP that has been installed on the system).

          You can't usually check php.ini settings for the web server using CLI commands, because the configurations are different, creating a php file with phpinfo() in it is the quick way (or our about page shows memory setting too).

          Thanks,

          adam.

          adama Adam Armstrong added a comment - This is a helpfully cryptic error from PHP, but it's likely that you need to increase the memory limit in php.ini. Make sure it's set in the correct php.ini, because there are almost always separate files for CLI and web (and usually separate files for each version of PHP that has been installed on the system). You can't usually check php.ini settings for the web server using CLI commands, because the configurations are different, creating a php file with phpinfo() in it is the quick way (or our about page shows memory setting too). Thanks, adam.
          steve.r.leroux.rfnow Steve Leroux added a comment - - edited

          I did a few more things.

          updated function in functions.inc.php

          function html_callback($buffer)
          {
              global $config;
              global $cache_html;    // Do not disclose version to unauthorized requests
              $version_param = $_SESSION['authenticated'] ? '?v=' . OBSERVIUM_VERSION : '';    // Define template strings for registered CSS/JS links and other elements
              $templates = [
                'css'    => '    <link href="%%STRING%%' . $version_param . '" rel="stylesheet" type="text/css" />' . PHP_EOL,
                'style'  => '    <style type="text/css">' . PHP_EOL . '%%STRING%%' . PHP_EOL . '  </style>' . PHP_EOL,
                'js'     => '    <script type="text/javascript" src="%%STRING%%' . $version_param . '"></script>' . PHP_EOL,
                'script' => '  <script type="text/javascript">' . PHP_EOL .
                            '  <!-- Begin' . PHP_EOL . '%%STRING%%' . PHP_EOL .
                            '  // End -->' . PHP_EOL . '  </script>' . PHP_EOL,
                // key-value
                'meta-equiv' => '    <meta http-equiv="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,
                'meta'       => '    <meta name="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,
              ];    // Process and replace resources in the buffer
              foreach ($templates as $type => $template) {
                  $uppercase_type = strtoupper($type);
                  //if (isset($GLOBALS['cache_html']['resources'][$type])) {
                  if (isset($GLOBALS['cache_html']['resources'][$type]) && is_array($GLOBALS['cache_html']['resources'][$type])) {
                      $resource_string = '<!-- ' . $uppercase_type . ' BEGIN -->' . PHP_EOL;
                      if ($type === 'meta-equiv' || $type === 'meta') {
                          foreach ($GLOBALS['cache_html']['resources'][$type] as $name => $content) {
                              //bdump($content);
                              $resource_string .= str_replace([ '%%STRING_name%%', '%%STRING_content%%' ], [ $name, $content ], $template);
                          }
                      } else {
                          foreach (array_unique($GLOBALS['cache_html']['resources'][$type]) as $content) {
                              $resource_string .= str_replace('%%STRING%%', $content, $template);
                          }
                      }
                      $resource_string .= '    <!-- ' . $uppercase_type . ' END -->' . PHP_EOL;
                      if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->') !== false) {
                          $buffer = str_replace('<!-- ##' . $uppercase_type . '_CACHE## -->' . PHP_EOL, $resource_string, $buffer);
                      }
                  } else {
                      // Clean template string
                      if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->') !== false) {
                          $tmp = $buffer;
                          $buffer = str_replace('<!-- ##' . $uppercase_type . '_CACHE## -->', '', $tmp);
                      }
                  }
              }    // Replace placeholders in the buffer with actual values
              $replacements = [
                '##TITLE##'      => html_callback_build_title(),
                '##PAGE_PANEL##' => $GLOBALS['cache_html']['page_panel'],
                '##UI_ALERTS##'  => implode(PHP_EOL, (array)$GLOBALS['cache_html']['ui_alerts']),
              ];    // Return the modified HTML page source
              return array_str_replace($replacements, $buffer, TRUE);
          }
          

           

          Index.php

          ini_set('memory_limit', '1024M');

          //ob_start('html_callback');
          ob_start();
          

          //ob_end_flush();
          $buffer = ob_get_clean();
          $buffer = html_callback($buffer);
          echo $buffer;
           

           

          steve.r.leroux.rfnow Steve Leroux added a comment - - edited I did a few more things. updated function in functions.inc.php function html_callback($buffer) {     global $config;     global $cache_html;    // Do not disclose version to unauthorized requests     $version_param = $_SESSION[ 'authenticated' ] ? '?v=' . OBSERVIUM_VERSION : '' ;    // Define template strings for registered CSS/JS links and other elements     $templates = [       'css'    => '    <link href="%%STRING%%' . $version_param . '" rel="stylesheet" type="text/css" />' . PHP_EOL,       'style'  => '    <style type="text/css">' . PHP_EOL . '%%STRING%%' . PHP_EOL . '  </style>' . PHP_EOL,       'js'     => '    <script type="text/javascript" src="%%STRING%%' . $version_param . '"></script>' . PHP_EOL,       'script' => '  <script type="text/javascript">' . PHP_EOL .                   '  <!-- Begin' . PHP_EOL . '%%STRING%%' . PHP_EOL .                   '  // End -->' . PHP_EOL . '  </script>' . PHP_EOL,       // key-value       'meta-equiv' => '    <meta http-equiv="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,       'meta'       => '    <meta name="%%STRING_name%%" content="%%STRING_content%%" />' . PHP_EOL,     ];    // Process and replace resources in the buffer     foreach ($templates as $type => $template) {         $uppercase_type = strtoupper($type);         //if (isset($GLOBALS['cache_html']['resources'][$type])) {         if (isset($GLOBALS[ 'cache_html' ][ 'resources' ][$type]) && is_array($GLOBALS[ 'cache_html' ][ 'resources' ][$type])) {             $resource_string = '<!-- ' . $uppercase_type . ' BEGIN -->' . PHP_EOL;             if ($type === 'meta-equiv' || $type === 'meta' ) {                 foreach ($GLOBALS[ 'cache_html' ][ 'resources' ][$type] as $name => $content) {                     //bdump($content);                     $resource_string .= str_replace([ '%%STRING_name%%' , '%%STRING_content%%' ], [ $name, $content ], $template);                 }             } else {                 foreach (array_unique($GLOBALS[ 'cache_html' ][ 'resources' ][$type]) as $content) {                     $resource_string .= str_replace( '%%STRING%%' , $content, $template);                 }             }             $resource_string .= '    <!-- ' . $uppercase_type . ' END -->' . PHP_EOL;             if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->' ) !== false ) {                 $buffer = str_replace( '<!-- ##' . $uppercase_type . '_CACHE## -->' . PHP_EOL, $resource_string, $buffer);             }         } else {             // Clean template string             if (strpos($buffer, '<!-- ##' . $uppercase_type . '_CACHE## -->' ) !== false ) {                 $tmp = $buffer;                 $buffer = str_replace( '<!-- ##' . $uppercase_type . '_CACHE## -->' , '' , $tmp);             }         }     }    // Replace placeholders in the buffer with actual values     $replacements = [       '##TITLE##'      => html_callback_build_title(),       '##PAGE_PANEL##' => $GLOBALS[ 'cache_html' ][ 'page_panel' ],       '##UI_ALERTS##'  => implode(PHP_EOL, (array)$GLOBALS[ 'cache_html' ][ 'ui_alerts' ]),     ];    // Return the modified HTML page source     return array_str_replace($replacements, $buffer, TRUE); }   Index.php ini_set( 'memory_limit' , '1024M' ); //ob_start('html_callback'); ob_start(); //ob_end_flush(); $buffer = ob_get_clean(); $buffer = html_callback($buffer); echo $buffer;  
          steve.r.leroux.rfnow Steve Leroux added a comment - - edited

          Looks like a memory issue in the observium php code.
          The PHP memory limit was set to 1024M in the php.ini but I don't know why but since the upgrade, observium doesn't see it.
          To verify php is setup properly:
          php -r "echo ini_get('memory_limit');"
          1024M
          php -i | grep memory_limit memory_limit => 1024M => 1024M
           
          So I added "ini_set('memory_limit', '1024M');" to the top of index.php
          Now it works. 
           
          going to check if the php.ini file is valid.

          steve.r.leroux.rfnow Steve Leroux added a comment - - edited Looks like a memory issue in the observium php code. The PHP memory limit was set to 1024M in the php.ini but I don't know why but since the upgrade, observium doesn't see it. To verify php is setup properly: php -r "echo ini_get('memory_limit');" 1024M php -i | grep memory_limit memory_limit => 1024M => 1024M   So I added "ini_set('memory_limit', '1024M');" to the top of index.php Now it works.    going to check if the php.ini file is valid.

          PHP 8.1.2-1ubuntu2.19

          steve.r.leroux.rfnow Steve Leroux added a comment - PHP 8.1.2-1ubuntu2.19

          General questions and device support can be discussed in our Discord channel, click here to join.


          Please make and attach additional information about the device:

          • full snmp dump from device:

            snmpwalk -v2c -c <community> -t 3 -Cc --hexOutputLength=0 -Ih -ObentxU <hostname> .1 > myagent.snmpwalk
            snmpwalk -v2c -c <community> -t 3 -Cc --hexOutputLength=0 -Ih -ObentxU <hostname> .1.3.6.1.4.1 >> myagent.snmpwalk

            If device not support SNMP version 2c, replace -v2c with -v1.

          • If you have problems with discovery or poller processes, please do and attach these debugs:

            ./discovery.php -d -h <device>
            ./poller.php -d -h <device>

          • additionally attach device and/or vendor specific MIB files

          This comment is added automatically.

          bot Observium Bot added a comment - General questions and device support can be discussed in our Discord channel, click here to join . Please make and attach additional information about the device: full snmp dump from device: snmpwalk -v2c -c <community> -t 3 -Cc --hexOutputLength=0 -Ih -ObentxU <hostname> .1 > myagent.snmpwalk snmpwalk -v2c -c <community> -t 3 -Cc --hexOutputLength=0 -Ih -ObentxU <hostname> .1.3.6.1.4.1 >> myagent.snmpwalk If device not support SNMP version 2c, replace -v2c with -v1. If you have problems with discovery or poller processes, please do and attach these debugs: ./discovery.php -d -h <device> ./poller.php -d -h <device> additionally attach device and/or vendor specific MIB files This comment is added automatically.

          People

            adama Adam Armstrong
            steve.r.leroux.rfnow Steve Leroux
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: