Page 1 of 1

"Invalid argument" Problem!

Posted: Fri Feb 13, 2009 10:15 pm
by Spike
Hi,

i worked with lots of shop-systems, but i think your one is really easy to used and also good designed!! Great job, but i have a problem with the "Invalid argument" - Request.

I get this messages on the Front and at the Backend at every Action:


Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 18

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 41

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 18

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 41

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 18

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 41

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 18

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 41

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 18

Warning: Invalid argument supplied for foreach() in /www/htdocs/user/main/shop/system/library/cache.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/user/main/shop/system/library/cache.php:18) in /www/htdocs/user/main/shop/system/library/response.php on line 65


My server use PHP 5.2.6 ....

So, what´s wrong? I set the required folders and cache.php to 777, otherwise it will be crashed, but nothing changed! ;(

Can anyone help me?

Re: "Invalid argument" Problem!

Posted: Fri Feb 13, 2009 11:24 pm
by daelsta
Hey spike, i had the same problem.
You can put an .htaccess file in your web server's root directory and enter there:

php_value display_errors 0

save it.

This should do the trick.

Greetz daelsta

Re: "Invalid argument" Problem!

Posted: Fri Feb 13, 2009 11:38 pm
by Spike
Hey daelsta,

great - that´s it!! Thx!!

Greetz, Spike

Re: "Invalid argument" Problem!

Posted: Fri Feb 13, 2009 11:48 pm
by Daniel
php_value display_errors 0 is a quick fix but turns off error reporing.

the problem is php's glob function. it won't read files with in the cache directory.

I'm going to fix this properly using fopen.

Re: "Invalid argument" Problem!

Posted: Sat Feb 14, 2009 1:20 am
by daelsta
fixing the error would be the best solution  ;)

ps: daniel, just have to tell you that your new opencart is absolutely awsome. thanks for your work!

Re: "Invalid argument" Problem!

Posted: Sat Feb 14, 2009 1:35 am
by Daniel
Replace your cache file with this:

Code: Select all

<?php
final class Cache { 
	private $expire = 3600;

  	public function __construct() {
		$files = glob(DIR_CACHE . 'cache.*');
    	
		if ($files) {
			foreach ($files as $file) {
      			$time = end(explode('.', basename($file)));

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

	public function get($key) {
		$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
		
		if ($files) {
    		foreach ($files as $file) {
      			$handle = fopen($file, 'r');
      			$cache  = fread($handle, filesize($file));
	  
      			fclose($handle);

	      		return unserialize($cache);
   		 	}
		}
  	}

  	public function set($key, $value) {
    	$this->delete($key);
		
		$file = DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->expire);
    	
		$handle = fopen($file, 'w');

    	fwrite($handle, serialize($value));
		
    	fclose($handle);
  	}
	
  	public function delete($key) {
		$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
		
		if ($files) {
    		foreach ($files as $file) {
      			unlink($file);
    		}
		}
  	}
}
?>

The problem is that the glob function returns false and not array when nothing is found. Also I would check that you have set the right permission on the cache directory.

Re: "Invalid argument" Problem!

Posted: Sat Feb 14, 2009 1:51 am
by daelsta
seems like this fixed the error (folder permissions already were 777)

thanks