Fatal error: Uncaught exception 'Zend_Cache_Exception' with message > 'cache_dir must be a directory' - apache

After doing my code update. I got this error.
Could you help me figure this one out?
I gave 777 permission to all of the folders.
Thanks in advance!
Fatal error: Uncaught exception 'Zend_Cache_Exception' with message
'cache_dir must be a directory' in
C:\xampp\htdocs\mts\library\Zend\Cache.php:208 Stack trace: #0
C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php(154):
Zend_Cache::throwException('cache_dir must ...') #1
C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php(121):
Zend_Cache_Backend_File->setCacheDir('C:\xampp\htdocs...') #2
C:\xampp\htdocs\mts\library\Zend\Cache.php(152):
Zend_Cache_Backend_File->__construct(Array) #3
C:\xampp\htdocs\mts\library\Zend\Cache.php(93):
Zend_Cache::_makeBackend('File', Array, false, false) #4
C:\xampp\htdocs\mts\application\Bootstrap.php(22):
Zend_Cache::factory('Core', 'File', Array, Array) #5
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\BootstrapAbstract.php(636):
Bootstrap->_initCache() #6
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\BootstrapAbstract.php(589):
Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('cache') 7#
C:\xampp\htdocs\mts\library\Zend\Application\Bootstrap\Boots in
C:\xampp\htdocs\mts\library\Zend\Cache.php on line 208

Setting the cache in bootstrap
protected function _initCaching() {
$frontend = array(
'lifetime' => 7200,
'automatic_serialization' => true
);
$backend = array(
'cache_dir' => sys_get_temp_dir(), /**automatically detects**/
);
$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
Zend_Registry::set('cache', $cache);
}

Go to C:\xampp\htdocs\mts\library\Zend\Cache\Backend\File.php at line 154 and echo $value before the conditions. It should give you a directory address. Make sure that directory exists in your file system. Basically you need to set this path correctly in your zend configuration.

It's not about permission, ZF can't find the cache directory. Check if the directory you set in application.ini actually exists.
As you are on Windows machine, permissions shouldn't be a problem.

Related

can't test eloquent with php unit

I try to implement some unit tests with phpUnit, on a project that uses Eloquent. The installation is made with composer for both frameworks. But when I try to implement a simple example test, it fails loading database.php
the example test
include("database.php");
class ArticleControllerTest extends TestCase
{
public function testAccueil()
{
//récupère la date du jour
$a = \app\model\Article::first();
$this->assertInternalType("string", $a->titreGeneral);
}
}
Database.php
<?php
require 'vendor/autoload.php';
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'spectacles',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
$capsule->bootEloquent();
error message with these script (the database is in the right folder)
PHP Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
PHP Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
And error messages when I try to put the code in database.php directly in the example test :
PDOException: SQLSTATE[HY000] [2002] No such file or directory
I don't think the problem comes prom the paths (they are the right paths). Did I miss something ?
PDOException: SQLSTATE[HY000] [2002] No such file or directory means the database could not connect.
The other errors are clearly telling you that the script could not include the database.php file.
The paths are not correct. You are not properly understanding how include() works. Read http://php.net/manual/en/function.include.php.
In a nutshell, the following code expects the database.php file to exist in the same directory as the file itself, or on the include path.
include("database.php");
class ArticleControllerTest extends TestCase
{
...
These may also help:
Understanding include_path output PHP
Include Config and Database from other files

why chef-metal-ssh is failed

I was trying to follow https://github.com/double-z/chef-metal-ssh
I'm running the code below, it throws the exception:
[2015-01-19T06:03:39-06:00] ERROR: machineone had an error: ArgumentError: wrong number of arguments (2 for 0)
require 'chef_metal_ssh'
name = "one"
with_ssh_cluster("~/metal_ssh")
machine name do
action [:ready, :converge]
machine_options 'ip_address' => '10.62.56.209',
'ssh_options' => {
'user' => 'root',
'keys' => ['/home/chefuser/test.rsa']
}
files '/remote/path.txt' => { :content => 'foo' }
end
machine_execute name do
command "pwd" # this uses new_daemon_key to register with halo
end
I want to know what's wrong of this code. And I don't understand for with_ssh_cluster("~/metal_ssh") what content should be in "~/metal_ssh"? thanks.
I had to dig a little with the code to understand (I'm not using it).
According to the comment below found here
# cluster_path - path to the directory containing the vagrant files,
# which should have been created with the vagrant_cluster resource.
The "~/metal_ssh" file should be the Vagrantfile path.
chaf-metal-ssh is a driver for chef-metal, I'm not sure you're comfortable with chef-metal, so I would advise starting by reading This and This
I've found that the issue is I was using chef 12.0.3, and in line 109 of /usr/local/rvm/gems/ruby-2.0.0-p598/gems/chef-12.0.3/lib/chef/dsl/recipe.rb
resource.load_prior_resource(type, name)
But in chef-metal-ssh-0.1.2/lib/chef/resource/ssh_cluster.rb:18
it's defined as
def load_prior_resource
Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
end
so it throws
ArgumentError: wrong number of arguments (2 for 0)

Yii - How to access to model and call action in yiic

I have an action that prints "Hello World":
public function actionStart()
{
echo 'Hello World';
}
I will to run a cron job that calls this action every minute.
How I can do this with yiic ?
UPDATE:
I create console app. I have cron.php inside index.php:
<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once('framework/yii.php');
// we'll use a separate config file
$configFile='protected/config/c.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();
and config/c.php:
<?php
return array(
// This path may be different. You can probably get it from `config/main.php`.
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Cron',
'preload'=>array('log'),
'import'=>array(
'application.models.*',
'application.components.*',
),
// We'll log cron messages to the separate files
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron.log',
'levels'=>'error, warning',
),
array(
'class'=>'CFileLogRoute',
'logFile'=>'cron_trace.log',
'levels'=>'trace',
),
),
),
// Your DB connection
'db'=>array(
'class'=>'CDbConnection',
// …
),
),
);
and protected/commands/MyCommand.php:
<?php
class MyCommand extends CConsoleCommand
{
public function run($args)
{
$logs = Log::model()->findAll();
print_r($logs);
die();
}
}
when I run this:
$ ./protected/yiic my
I got this error:
PHP Error[2]: include(Log.php): failed to open stream: No such file or directory
in file /path/to/app/folder/framework/YiiBase.php at line 427
#0 /path/to/app/folder/framework/YiiBase.php(427): autoload()
#1 unknown(0): autoload()
#2 /path/to/app/folder/protected/commands/MyCommand.php(6): spl_autoload_call()
#3 /path/to/app/folder/framework/console/CConsoleCommandRunner.php(71): MyCommand->run()
#4 /path/to/app/folder/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run()
#5 /path/to/app/folder/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#6 /path/to/app/folder/framework/yiic.php(33): CConsoleApplication->run()
#7 /path/to/app/folder/protected/yiic.php(7): require_once()
#8 /path/to/app/folder/protected/yiic(3): require_once()
How I can fix this?
First you have to create a command: http://www.yiiframework.com/doc/guide/1.1/en/topics.console#creating-commands
Then you can acess your function by running this command:
yiic yourCommand start
You have to load your models in Console application.
Open console.php configuration file, and add this line under the line 'name'=>'My Console Application',
'import'=>array(
'application.models.*'
),
It should work.
It seems that your don't have such 'log.php' file you are including.
maybe try this from console :
touch /path/to/app/folder/protected/log.php
You should have another error message then (or it will run smoothly).
Just open your yiic.php file check framework path in it.

call a custom observer in fuelphp

i create a custom Observer :
class Observer_Test extends Orm\Observer
{
public function after_insert(Orm\Model $model)
{
\Log::info('Succesfully created new object of class '.get_class($model));
}
}
i put this code in app/classes/observer/test.php
and i called from my model in app/classes/model/
this my observer
protected static $_observers = array(
'Observer\Observer_Test' => array(
'events' => array('after_insert'),
),
);
and i got an error message like this
ErrorException [ Error ]: Uncaught exception 'Fuel\Core\FuelException'
with message 'Unable to create or write to the log file. Please check
the permissions on
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/app/logs/' in
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/log.php:77
Stack trace: #0 [internal function]: Fuel\Core\Log::_init() #1
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/autoloader.php(364):
call_user_func('Log::_init') #2
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/autoloader.php(247):
Fuel\Core\Autoloader::init_class('Log') #3 [internal function]:
Fuel\Core\Autoloader::load('Log') #4
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/base.php(91):
spl_autoload_call('Log') #5
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/classes/error.php(117):
logger(400, 'Error - Observe...') #6
/Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER/fuel/core/bootstrap.php(71):
Fuel\Core\Error::exception_handler(Object(UnexpectedValueException))
i think i wrong when i called or put the observer, what is the best practices for creating an observer?
as I see, the error says that there is not enough permission to write to that directory, and observer itself is working. to make sure, just replace Log::() call with something like die('WORKS!'); instead.
To fix the problem, so the logs would start writing, try to fix the directory permissions. I'm not sure how MacOSX handles this but this might heenter code herelp you:
cd /Applications/XAMPP/xamppfiles/htdocs/MPOSSERVER
find . -type f -exec chmod 666 {} \;
find . -type d -exec chmod 777 {} \;
1st command will cd to you web project
2nd will make all files in that directory to chmod to 666 (read/write by everyone)
3rd command will make read/write/execute by everyone
Hope that helps
Good luck :)

CakePHP 2.0 + Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]

Im using 000webhost as a way to host my portfolio of websites. However Im getting this error thrown in which doesn't happen to me on localhost.
Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]
This is the code it seems to be referring to,
public function add() {
$this->render();
if($this->request->is('post')){
$file = $this->request->data['Upload']['file'];
if($this->Upload->save($this->data) && move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4'))
{
$this->Session->setFlash('<p class="uploadflash">The upload has been saved</p>', true);
$this->redirect(array('controller'=>'Uploads', 'action' => 'watch', $this->Upload->id));
} else {
$this->Session->setFlash('<p class="loginerror">The upload could not be saved, mp4 files can be saved only.</p>', true);
}
}
}
Any ideas as to why this is happening?
Also in addition my Elements are not showing up on this online hosting either?
I get thrown this error on the page
Element Not Found: Elements/uploads/recentuploads.ctp
Does anyone else seem to have this problem??
Upon further inspection I have found that the server does not allow file upload sizes to exceed 2mb, in this instance PHP throws the error above.