0

I encountered strange error with my php-fpm 5.6.30 with OPcache v7.0.6-dev on ubuntu server. I got error at /vendor/monolog/monolog/src/Monolog/Logger.php file concerning array_keys(static::$levels) code in it:

array_keys() expects parameter 1 to be array, object given

The static::$levels property is defined in the top of Logger.php file as array:

protected static $levels = array(
    self::DEBUG     => 'DEBUG',
    self::INFO      => 'INFO',
    self::NOTICE    => 'NOTICE',
    self::WARNING   => 'WARNING',
    self::ERROR     => 'ERROR',
    self::CRITICAL  => 'CRITICAL',
    self::ALERT     => 'ALERT',
    self::EMERGENCY => 'EMERGENCY',
);

This code was installed via composer and never edited manually, so there is no reasons for the file to be changed.

When I look at my laravel.log, I see that something has changed the code behaviour, so lines at the log changed their format:

[2018-05-16 00:19:22] production.INFO: blabla
[2018-05-16 00:20:04] production.[object] (DateTimeZone: {"timezone_type":3,"timezone":"UTC"}): blablabla

The key fact is that when I opened the file using nano, added a comment line into it and saved, the bug disappears. It means that the wrong code was in the opcache, not in the code of the framework.

To conclude, the bytecode of Logger.php was somehow changed and php saw object with DateTimeZone objects in it rather than an array of strings.

The question is - how could the cached bytecode be changed without being totally crashed? What on earth can do this? Can high memory consumption lead to such unexpected changes?

shukshin.ivan
  • 11,075
  • 4
  • 53
  • 69

1 Answers1

1

We had the same issue in our project (php 5.6.30, opcache v7.0.6-dev). To solve the problem we analyzed the opcache settings and found that interned_strings_buffer was 4Mb. Raising this value to 64 Mb we solved the problem.

  • 1
    side note: "b" stands for "bit", while "B" stands for "byte", so you rather wanted to say "4MB" etc... – Marcin Orlowski Jun 05 '18 at 13:53
  • How did you guess that? Why is this particular settings value so important? – shukshin.ivan Jun 05 '18 at 16:46
  • We install an opcache monitor on our server and we notice that when the problem occurs the `interned_string_buffers` usage was full. I Follow this [article](https://www.scalingphpbook.com/blog/2014/02/14/best-zend-opcache-settings.html) for further information about Opcache settings – Andrea Quintino Jun 06 '18 at 07:57