Post by labeshops » Sat Jul 08, 2023 6:45 pm

I keep getting this error over and over in my error log - it's the only error in fact. I cannot figure out why or how to fix it. The only thing I can find about unlink errors is that it is caused by trying to use php 8x for opencart v3 (I have 3.0.3.2), but I have triple checked and my server is running php v7.4 like it always has. It's driving me batty! Any ideas? I've cleared the cache over and over again and just keep getting this error.

2023-07-08 10:33:53 - PHP Warning: unlink(/home/xxxxx/domains/xxxx/public_html/system/storage/cache/cache.catalog.language.1688816033):
No such file or directory in /home/xxxx/domains/xxxx/public_html/system/library/cache/file.php on line 68


this is my file.php file which is the default file of v3.0.3.2 - line 68 unlink($file);

Code: Select all

<?php
namespace Cache;
class File {
	private $expire;

	public function __construct($expire = 3600) {
		$this->expire = $expire;

		$files = glob(DIR_CACHE . 'cache.*');

		if ($files) {
			foreach ($files as $file) {
				$time = substr(strrchr($file, '.'), 1);

				if ($time < time()) {
					if (file_exists($file)) {
						unlink($file);
					}
				}
			}
		}
	}

	public function get($key) {
		$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');

		if ($files) {
			$handle = fopen($files[0], 'r');

			flock($handle, LOCK_SH);

			$data = fread($handle, filesize($files[0]));

			flock($handle, LOCK_UN);

			fclose($handle);

			return json_decode($data, true);
		}

		return false;
	}

	public function set($key, $value) {
		$this->delete($key);

		$file = DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.' . (time() + $this->expire);

		$handle = fopen($file, 'w');

		flock($handle, LOCK_EX);

		fwrite($handle, json_encode($value));

		fflush($handle);

		flock($handle, LOCK_UN);

		fclose($handle);
	}

	public function delete($key) {
		$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');

		if ($files) {
			foreach ($files as $file) {
				if (file_exists($file)) {
				unlink($file);
				}
			}
		}
	}
}
Last edited by labeshops on Sat Jul 08, 2023 8:24 pm, edited 1 time in total.

Running Opencart v3.0.3.9 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by SohBH » Sat Jul 08, 2023 7:29 pm

Suppress the warning using @ operator:

Code: Select all

@unlink($file);

View all extensions | Request custom work | Pricing | Contact Me


User avatar
Active Member

Posts

Joined
Mon Nov 02, 2020 12:01 am
Location - Malaysia

Post by ADD Creative » Sat Jul 08, 2023 8:08 pm

Make sure you have the following bug fix, which was only included in 3.0.3.7. https://github.com/opencart/opencart/co ... 990171168e

The problem was the language was trying to read the 'language' cache, but writing the 'catalog.language' cache. Give it a try and see if it reduces the number of unlink warnings.

If that fix is applied and you a still getting warnings. It could be something else. However, you will always get some unlink warnings. As you can get the problem of:
Process 1 checks if the old cache file exists. Which it does.
Process 2 checks if the old cache file exists. Which it does.
Process 1 deletes the old cache file with unlink. Which will be successful.
Process 2 deletes the old cache file with unlink. Which will fail as process 1 has already deleted it.

As this is just cache clean up, as long as the warning is not being display and only logged it won't cause any problems. After applying the above fix. If you only the errors occasionally, say less than once a day on a busy site, then suppress the error as suggested by SohBH. If you still see a lot you might want to investigate further.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by labeshops » Sat Jul 08, 2023 8:24 pm

Thank you! That seems to have solved the error problem!

However, I do have a bigger issue that apparently fixing this error didn't solve. I'm sending you a dm.

Running Opencart v3.0.3.9 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by paulfeakins » Mon Jul 10, 2023 6:07 pm

SohBH wrote:
Sat Jul 08, 2023 7:29 pm
Suppress the warning using @ operator:

Code: Select all

@unlink($file);
No, the way to fix problems is not to just hide the error message *facepalm*.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: No registered users and 48 guests