Page 1 of 1

file_get_contents & Unlink Error.

Posted: Sun Sep 16, 2012 4:48 am
by HATEPOLICY
Just wanted to post what I got in my error logs on 1.5.4.1

Code: Select all

PHP Warning:  unlink(/home4/bla/public_html/system/cache/cache.product.total.1.0.1.6a5cd25fa692974e13bf32bb2cf9fa87.1347724197) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home4/bla/public_html/system/library/cache.php on line 45
and

Code: Select all

PHP Warning:  file_get_contents(/home4/bla/public_html/system/cache/cache.product.total.1.0.1.d9f1ed5791e772f1c55fc9cc989a64b8.1347741244) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home4/bla/public_html/system/library/cache.php on line 9
Should I worry?
Thanks.

Re: file_get_contents & Unlink Error.

Posted: Sun Sep 16, 2012 5:55 am
by anung
Check your cache folder permission is writeble or not, if not, make the folder writeble (777 or 755).

Re: file_get_contents & Unlink Error.

Posted: Sun Sep 16, 2012 7:29 am
by HATEPOLICY
Thanks for ur reply,

It was on 755, changed to 777, hope that sorts it.

Cheers.

Re: file_get_contents & Unlink Error.

Posted: Sun Sep 16, 2012 8:32 pm
by HATEPOLICY
Nope, same errors today also...

So, should I be worried? :)

Thanks!

Re: file_get_contents & Unlink Error.

Posted: Sun Sep 16, 2012 9:57 pm
by i2Paq
Sometimes a cache files is not existing anymore, that is when you get these errors (I believe).

There are some topics about this on our forums.

Re: file_get_contents & Unlink Error.

Posted: Mon Sep 17, 2012 4:02 am
by HATEPOLICY
Thx for ur reply I2Paq, legit bug then I guess...don't worry I am not going to post it in the Elite forums ;)

Did some reading on cache, kinda got lost tho!
Couldn't find much in regards to my specific errors.

Will report back if anything else pops up.

Got this now also:

Code: Select all

Undefined index:  last_order_id in /home4/bla/public_html/catalog/controller/checkout/success.php on line 68
Cheers.

Re: file_get_contents & Unlink Error.

Posted: Sat Nov 17, 2012 9:19 pm
by renatogs
I have same errors!

Re: file_get_contents & Unlink Error.

Posted: Sun Nov 25, 2012 12:13 am
by renatogs
Did you fix the error?

My cache folder everyday have 3000 arquivos cache.

I think it isnĀ“t normal!

Re: file_get_contents & Unlink Error.

Posted: Fri Jan 11, 2013 9:39 pm
by dachiaru
I have same errors!

you solved the problem?

Re: file_get_contents & Unlink Error.

Posted: Wed Jan 16, 2013 9:33 pm
by jfn99
I'm having the same problem... any one found a solution? please post!

Re: file_get_contents & Unlink Error.

Posted: Thu Jan 17, 2013 2:45 am
by rph
Just clear the errors. They can be ignored.

Re: file_get_contents & Unlink Error.

Posted: Tue Jan 22, 2013 1:56 am
by jfn99
Any way to stop these errors to show up?

Code: Select all

2013-01-21 16:47:32 - PHP Warning:  file_get_contents(/home/******/public_html/system/cache/cache.product.total.2.0.1.443d1b471d5c27fd802cd68f8cd126c3.1358790436) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/******/public_html/system/library/cache.php on line 9
2013-01-21 17:03:22 - PHP Warning:  file_get_contents(/home/******/public_html/system/cache/cache.product.total.2.0.1.472c2fef3b8bdbd661efd29bed8ca590.1358791401) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/******/public_html/system/library/cache.php on line 9
2013-01-21 17:03:22 - PHP Warning:  file_get_contents(/home/******/public_html/system/cache/cache.product.total.2.0.1.308ccb6cbc0aa0ecc7a86b303e9f0005.1358791401) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/******/public_html/system/library/cache.php on line 9
2013-01-21 17:26:57 - PHP Warning:  unlink(/home/******/public_html/system/cache/cache.product.total.2.0.1.a2b2d8fa2854da5a48cdb889f8f8a628.1358792817) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/******/public_html/system/library/cache.php on line 45
2013-01-21 17:30:51 - PHP Warning:  unlink(/home/******/public_html/system/cache/cache.product.total.2.0.1.f2ca1894d140cc8f60bb9cbbf2422ee0.1358793051) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/******/public_html/system/library/cache.php on line 45
2013-01-21 17:30:52 - PHP Warning:  unlink(/home/******/public_html/system/cache/cache.product.total.2.0.1.dfb9aaea846ac6b06d365047b2819d4f.1358793051) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/******/public_html/system/library/cache.php on line 45
2013-01-21 17:30:52 - PHP Warning:  unlink(/home/******/public_html/system/cache/cache.product.total.2.0.1.e30e83954c1fe05186a017655f9fb23f.1358793051) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/******/public_html/system/library/cache.php on line 45
2013-01-21 17:30:52 - PHP Warning:  unlink(/home/******/public_html/system/cache/cache.product.total.2.0.1.22bd9de096ed92bc164d89bd3f5fd1e2.1358793051) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/******/public_html/system/library/cache.php on line 45

Re: file_get_contents & Unlink Error.

Posted: Tue Feb 05, 2013 7:45 pm
by MikeSCC
Hi,

I am also getting these errors - was there a solution for this issue?

Thanks,

Mike

Re: file_get_contents & Unlink Error.

Posted: Wed Feb 06, 2013 12:34 am
by Daniel
they should turn up less in the latest version as i have removed caching for products and categories.

there is not much that can be done to stop this. you are talking fractions of seconds between selecting a file to be deleted and it being already deleted. just depends on the traffic on your site.

Re: file_get_contents & Unlink Error.

Posted: Wed Feb 06, 2013 1:06 am
by MikeSCC
Daniel wrote:they should turn up less in the latest version as i have removed caching for products and categories.

there is not much that can be done to stop this. you are talking fractions of seconds between selecting a file to be deleted and it being already deleted. just depends on the traffic on your site.
Thanks for your help.

Cheers,

Mike

Re: file_get_contents & Unlink Error.

Posted: Thu Aug 01, 2013 9:00 pm
by JonnyR
Hi Guys! Just found this module http://www.opencart.com/index.php?route ... n_id=13067. It should help with such errors.

Re: file_get_contents & Unlink Error.

Posted: Sat Aug 03, 2013 1:21 pm
by ocatfni
We were seeing similar errors. We have an extension installed that was creating tens of thousands of cache files (a hook added in the "getTotalProducts(...)" function). In addition to errors like these, we found the site slowed to a crawl. We have improved the situation greatly, perhaps resolved it altogether, by modifying the "upload/system/library/cache.php" script.

The version of OpenCart we are using is 1.5.1.3.1. I've peeked at the OpenCart 1.5.6 version and, though the code has changed slightly between the two versions, it appears the reworking we did remains applicable and will be beneficial to those having similar problems with degraded performance and cache file unlinking errors.

In a nutshell, the current caching implementation requests a "glob(...)" in the cache directory at instantiation (in version 1.5.1.3.1 but not in version 1.5.6) and also again every time the "get(...)" and "set(...)" (via the delete(...)) functions are called. The "glob(...)" function is expensive, especially with tens of thousands of directory entries, and this was devastating to performance. Furthermore, in version 1.5.1.3.1, a call to "clearstatcache(...)" was being made after each unique cache file unlink. A single clearing of the cache after completion would suffice. For race conditions where a cache file is unlinked by another process, there is currently no "@" prefix to the "unlink(...)" call to hide the error (which really isn't an error because, ultimately, the file is gone as desired).

So ... to improve in these areas ... try replacing the contents of the "upload/system/library/cache.php" script with these contents (and let the forum know if it helps -- maybe the ideas here will find their way into the code base) :

Code: Select all

<?php

  final class Cache
  {
    private $expire = 3600;
    private $files = NULL;

    public function __construct()
    {
      $files = @glob(DIR_CACHE . 'cache.*');
      if($files === FALSE)
      {
        $files = array();
      }

      foreach($files as $cnt => $file)
      {
        $time = substr(strrchr($file, '.'), 1);
        if($time < time())
        {
          if(@file_exists($file))
          {
            @unlink($file);
          }
          unset($files[$cnt]);
        }
      }
      clearstatcache();
      $files = array_values($files);

      $this->files = $files;
    }

    public function get($key)
    {
      $cache = NULL;

      $target = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.';
      $length = strlen($target);
      foreach($this->files as $file)
      {
        if(strncmp($file, $target, $length) == 0)
        {
          $cache = @file_get_contents($file);
          if($cache)
          {
            $cache = unserialize($cache);
          }
        }
      }

      return $cache;
    }

    public function set($key, $value)
    {
      $file = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.' . (time() + $this->expire);
      $handle = @fopen($file, 'w');
      if($handle)
      {
        @fwrite($handle, serialize($value));
        @fclose($handle);
        $this->files[] = $file;
      }
    }

    public function delete($key)
    {
      $target = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.';
      $length = strlen($target);
      foreach($this->files as $file)
      {
        if(strncmp($file, $target, $length) == 0)
        {
          if(@file_exists($file))
          {
            @unlink($file);
          }
        }
      }
      clearstatcache();
    }
  }

?>
Good luck!

Re: file_get_contents & Unlink Error.

Posted: Thu Oct 24, 2013 10:31 am
by byens
JonnyR wrote:Hi Guys! Just found this module http://www.opencart.com/index.php?route ... n_id=13067. It should help with such errors.
Thanks after added this mod, unlink error was gone. But php file gets contents still there
ocatfni wrote:We were seeing similar errors. We have an extension installed that was creating tens of thousands of cache files (a hook added in the "getTotalProducts(...)" function). In addition to errors like these, we found the site slowed to a crawl. We have improved the situation greatly, perhaps resolved it altogether, by modifying the "upload/system/library/cache.php" script.

The version of OpenCart we are using is 1.5.1.3.1. I've peeked at the OpenCart 1.5.6 version and, though the code has changed slightly between the two versions, it appears the reworking we did remains applicable and will be beneficial to those having similar problems with degraded performance and cache file unlinking errors.

In a nutshell, the current caching implementation requests a "glob(...)" in the cache directory at instantiation (in version 1.5.1.3.1 but not in version 1.5.6) and also again every time the "get(...)" and "set(...)" (via the delete(...)) functions are called. The "glob(...)" function is expensive, especially with tens of thousands of directory entries, and this was devastating to performance. Furthermore, in version 1.5.1.3.1, a call to "clearstatcache(...)" was being made after each unique cache file unlink. A single clearing of the cache after completion would suffice. For race conditions where a cache file is unlinked by another process, there is currently no "@" prefix to the "unlink(...)" call to hide the error (which really isn't an error because, ultimately, the file is gone as desired).

So ... to improve in these areas ... try replacing the contents of the "upload/system/library/cache.php" script with these contents (and let the forum know if it helps -- maybe the ideas here will find their way into the code base) :

Code: Select all

<?php

  final class Cache
  {
    private $expire = 3600;
    private $files = NULL;

    public function __construct()
    {
      $files = @glob(DIR_CACHE . 'cache.*');
      if($files === FALSE)
      {
        $files = array();
      }

      foreach($files as $cnt => $file)
      {
        $time = substr(strrchr($file, '.'), 1);
        if($time < time())
        {
          if(@file_exists($file))
          {
            @unlink($file);
          }
          unset($files[$cnt]);
        }
      }
      clearstatcache();
      $files = array_values($files);

      $this->files = $files;
    }

    public function get($key)
    {
      $cache = NULL;

      $target = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.';
      $length = strlen($target);
      foreach($this->files as $file)
      {
        if(strncmp($file, $target, $length) == 0)
        {
          $cache = @file_get_contents($file);
          if($cache)
          {
            $cache = unserialize($cache);
          }
        }
      }

      return $cache;
    }

    public function set($key, $value)
    {
      $file = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.' . (time() + $this->expire);
      $handle = @fopen($file, 'w');
      if($handle)
      {
        @fwrite($handle, serialize($value));
        @fclose($handle);
        $this->files[] = $file;
      }
    }

    public function delete($key)
    {
      $target = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.';
      $length = strlen($target);
      foreach($this->files as $file)
      {
        if(strncmp($file, $target, $length) == 0)
        {
          if(@file_exists($file))
          {
            @unlink($file);
          }
        }
      }
      clearstatcache();
    }
  }

?>
Good luck!
Thanks
I will try this by replacing my cache.php

Re: file_get_contents & Unlink Error.

Posted: Thu Oct 24, 2013 6:52 pm
by rph
ocatfni wrote: For race conditions where a cache file is unlinked by another process, there is currently no "@" prefix to the "unlink(...)" call to hide the error (which really isn't an error because, ultimately, the file is gone as desired).
OpenCart has its own error handler so error suppression won't do anything.