0

I have a simple cache mechanism:

$settings = @include('/var/www/cache/settings.php');
if ($settings === false)
{
    $settings = get it from DB
    file_put_contents('/var/www/cache/settings.php', '<?php return '.var_export($settings, true).';', LOCK_EX);
}

it works fine, but as seeing the error logs (I do log the surpressed errors too) it happens often: about 30 times a day. I have more visitors, it doesnt happens often - but it only should happen ONCE! When this file doesnt exists. Still, it happens frequently. What can it be? Its not a facebook-like page to have millions of visitors. Mightbe BOT-s are reading the site too often and multiple calling can cause concurrency?

Edit: no, its not duplicated, you can all see I applied absolute path.

John Smith
  • 6,129
  • 12
  • 68
  • 123
  • 1
    delete the code which removes the file, then you won't need to keep adding it back :/ why use a file at all when the settings are in the db? – Lawrence Cherone Sep 03 '19 at 19:23
  • .... there is no such code – John Smith Sep 03 '19 at 19:23
  • 1
    Log the [current working directory](https://www.php.net/manual/en/function.getcwd.php) when the miss happens. Swap out the `@include` call with a `file_exists` in the short term for debugging purposes. – ficuscr Sep 03 '19 at 19:27
  • 1
    Possible duplicate of [Are PHP include paths relative to the file or the calling code?](https://stackoverflow.com/questions/7378814/are-php-include-paths-relative-to-the-file-or-the-calling-code) – ficuscr Sep 03 '19 at 19:29
  • @ficuscr nope, you can clearly see that I applied absolute paths – John Smith Sep 03 '19 at 19:53
  • 1
    Absolute to what? It's not a URI. It is relative to the script. Maybe at least try my suggestion? – ficuscr Sep 03 '19 at 19:56
  • ok, I edited to be 101% sure – John Smith Sep 03 '19 at 19:58
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198896/discussion-between-ficuscr-and-john-smith). – ficuscr Sep 03 '19 at 19:59

0 Answers0