Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Cache file ../cache/easytablebooking/bookings_all-10 could not be written

Hello fellow phalconeers

Everytime the function 'getBookings' is called and it tries to save the write to the file it throws the error: Cache file ../cache/easytablebooking/bookings_all-10 could not be written

the folder ../cache/easytablebooking/ has the permissions chmod -R 775 and owner the owner is www-data:www-data

The modelsCache service who caches the models works fine, but this class doesn't.

It does create the file in the correct directory, but cannot write to it.

Do you guys have an idea?

OS: Ubuntu 14.04 PHP-V: 5.6.20

<?php

namespace EasyTableBooking\Cache;

use Phalcon\Cache\Backend\File as File; use Phalcon\Cache\Frontend\Output as FrontOutput; use EasyTableBooking\Bookings\EasyTableBookingBookings; use EasyTableBooking\Authorize\EasyTableBookingAuthorization;

class EasyTableBookingCache {

/**
* Cache object
* @var File
*/

protected $EasyTableBookingCache;

/**
* @var EasyTableBookingBookings
*/

protected $EasyTableBookingBookings;

/**
* Unique restaurant identifier
* @var integer
*/

protected $resellerChainID;

/**
* Unique cache suffix
* @var string
*/

private $suffix;

public function __construct($resellerChainID) {

    $EasyTableBookingAuthorization  = new EasyTableBookingAuthorization($resellerChainID);
    $this->EasyTableBookingBookings = new EasyTableBookingBookings($EasyTableBookingAuthorization);

    $this->suffix = $resellerChainID;

    $frontCache = new FrontOutput(
        array(
            'lifetime' => 30
        )
    );

    $this->EasyTableBookingCache = new File(
        $frontCache,
        array(
            'cacheDir' => '/cache/easytablebooking/'
        )
    );
}

public function getBookings($refresh = false) {

    $bookings = $this->EasyTableBookingCache->get('bookings_all-' . $this->suffix, 15);

    if($bookings !== null && $refresh === false):
        return $bookings;
    else:

        $bookings = $this->EasyTableBookingBookings->getBookings();

        if($bookings):

            $this->saveBookings($bookings);

            return $bookings;
        else:
            return false;
        endif;
    endif;
}

public function saveBookings($bookings) {

    $save = $this->EasyTableBookingCache->save('bookings_all-' . $this->suffix, $bookings, 15);

    if($save):
        return true;
    else:
        return false;
    endif;
}

}



64.1k
edited Aug '16

i would try if using aboslute paths to be sure where app is trying to write. ( in all my projects i have define('app path', '/var/www/whatever.com/') so i can specify absolute path each and every time.

Now.. whats the output of

stat var/www/myapp or whatever /cache/easytablebooking/

and also you need to make sure its parent is also writable by the group



2.4k
Accepted
answer

I found the problem it was:

use Phalcon\Cache\Frontend\Output as FrontOutput

Instead it should be - For writing to a file:

should be use Phalcon\Cache\Frontend\Data as FrontData