Jump to content

/cache/class_index.php is not writable, please give write permissions (chmod 666) on this file.


Recommended Posts

  • 4 weeks later...

I have the same issue, but when i try to delete the file or update the attribute to 666 the system reset it to 664 some second later

 

/cache/class_index.php is not writable, please give write permissions (chmod 666) on this file

 

The error is really annoing when you need to update a great amount of item

Link to comment
Share on other sites

From the log of my host i find a lot of line like this

 

[Fri Feb 14 16:31:54 2014] [error] [client 66.249.64.3:37224] - www.big-foot.it - AH01215: [Fri Feb 14 16:31:54 2014] [warn-phpd] mmap cache can't open /web/htdocs/www.big-foot.it/home/cache/class_index.php - Stale file handle (pid 6562), referer http://www.big-foot.it/it/tattici/3-mav1.html

Link to comment
Share on other sites

My hosting seems to go in the wrong direction to resolve my issue. 

They say all the files that use php need to be set il CHMOD 755.

I have made some test and seems to be some istruction in the prestashop code that reset the CHMOD of the file to 664 when you open a page on the site.

 

Do you know if there is some istruction (and where it is) that rewrite the class_index.php in cache folder?

Link to comment
Share on other sites

The file is created in Autoload::generateIndex() method. (classes/Autoload.php) and it seems that it tries to set the perms to 666 there. Please give it a try with 755. 

Normally you should use an override, but in a case where you deal with the very file determining which classes are overriden, it's better to work on Autoload.php file directly. Anyway, please do not forget to take a backup first.

Edited by prestashopninja (see edit history)
Link to comment
Share on other sites

Ok, i have found the function where the CHMOD is setted and in this function have found
 
@chmod($filename, 0664);
 
I have put it in 666 and now the file class_index.php is created in 666 (and apparently the site is working good)
My question now is: if this file need to be in 666 why the code create it in 664??
 
I try to put under stress the site to see if the error is still shown. I'll keep you updated
Here the modified function 
 

 

public function generateIndex()

{
$classes = array_merge(
$this->getClassesFromDir('classes/'),
$this->getClassesFromDir('override/classes/'),
$this->getClassesFromDir('controllers/'),
$this->getClassesFromDir('override/controllers/')
);
ksort($classes);
$content = '<?php return '.var_export($classes, true).'; ?>';
 
// Write classes index on disc to cache it
$filename = $this->root_dir.Autoload::INDEX_FILE;
if ((file_exists($filename) && !is_writable($filename)) || !is_writable(dirname($filename)))
{
header('HTTP/1.1 503 temporarily overloaded');
// Cannot use PrestaShopException in this context
die('/cache/class_index.php is not writable, please give write permissions (chmod 666) on this file.');
}
else
{
$filename_tmp = tempnam(dirname($filename), basename($filename.'.'));
if($filename_tmp !== FALSE and file_put_contents($filename_tmp, $content, LOCK_EX) !== FALSE)
            {
rename($filename_tmp, $filename);
                @chmod($filename, 0666);
}
            else
            {
// $filename_tmp couldn't be written. $filename should be there anyway (even if outdated),
// no need to die.
error_log('Cannot write temporary file '.$filename_tmp);
}
}
 
$this->index = $classes;
}
Link to comment
Share on other sites

×
×
  • Create New...