Cakephp Fatal error rendering issue - cakephp

I'm using Cakephp version 2.2.4 and it is unable to render Fatal error messages (It shows weird characters).
When i remove the line 'handler' => 'ErrorHandler::handleError' from core file, PHP displays the Fatal error correctly.
Here is a link to screenshot of what i see
Here's the content of my core file (Error related):
Configure::write('debug', 2);
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
));
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
'trace' => true
));
Thanks

Update to the recently released CakePHP version 2.2.5, which apparently fixed some problems in ExceptionHandler.

I just checked and found that I was referencing a model I had not loaded. Loading the model (Actually referencing it through the current model) solved the problem for me.

Related

Different routing behaviour according to debug level

I have a cake php site which lives in a subdirectory on my site called secure, so
https://example.com/secure
When the debug level is 1 or 2 then it works fine, but if I change the debug level to 0 (with Configure::write('debug', 0);) and go to that address I get this error:
Error: The requested address '/secure/index.php/secure/' was not found on this server.
I have the following two routes in routes.php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/secure', array('controller' => 'pages', 'action' => 'display', 'home'));
How can I get it to work with debug set to 0? I could move the whole site into example.com, but I'd like that to be a last resort.
Routing is not being affected by the debug level.
Your problem is that you are pointing the route to the home page, which is only available in debug mode because it reveals possibly sensitive system information, see app/View/Pages/home.ctp
if (!Configure::read('debug')):
throw new NotFoundException();
endif;
Test your routes with a custom page and everything should work fine.

CakePHP cache permissions issues

This week I have moved a CakePHP application on the server so that it is served from C:\path\current\ where current is a symlink to C:\path\versions[date]. Previously the app was in C:\inetpub\wwwroot.
Thus each time I deploy changes, I make a new version of the app and the deploy script updates the symlink. In order to avoid having to re-create the temp dir each time, I've moved the temp dir to C:\path\app_tmp\ - the deploy script drops a symlink at app\tmp pointing to this temp dir.
The server is Windows Server 2008 R2 and the web server is IIS7. C:\path\app_tmp\ has full permissions (Everyone has Full Control).
Since making the change to the location of the app and the tmp dir, users are reporting sporadic instances of warnings appearing at the top of the page. The app is in debug=0 but these do not appear in the error log.
Examples:
Warning:
unlink(C:\path\app_tmp\cache\models\prefix_cake_model_default_app_modelname):
Permission denied in
C:\path\versions[date]\www\lib\Cake\Cache\Engine\FileEngine.php on
line 254
Warning:
SplFileInfo::openFile(C:\path\versions[date]\www\app\tmp\cache\models\prefix_cake_model_default_app_modelname):
failed to open stream: Permission denied in
C:\path\versions[date]\www\lib\Cake\Cache\Engine\FileEngine.php on
line 313
(actual paths/model names obfuscated)
Here is what I have in core.php:
$engine = 'File';
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
if (!isset($_SERVER['HTTP_HOST'])) {
$prefix = 'cmd_';
}
else {
$prefix = $_SERVER['HTTP_HOST'] . '_';
}
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration,
'mask' => 0666
));
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration,
'mask' => 0666
));
I have this in bootstrap.php:
Cache::config('default', array('engine' => 'File'));
Any suggestions? I have a feeling that perhaps the permissions aren't being inherited properly from the app\tmp symlink to the actual tmp dir, but on the other hand the error logs seem to write correctly and these errors are only sporadic.
One idea i had was to switch to using Wincache but then I can't find any information on how I clear the model cache when I've got a database change to deploy (currently I can just clear the model cache with a grunt task).
I haven't been able to resolve this while sticking to using the default file caching. I've switched the application to using Wincache. To clear model cache when a database change is made, I've written a short script to execute:
Cache::clear('_cake_model_');
This has to be done in the browser because CLI uses a different cache from IIS, but I've made it "gruntable" by using grunt-shell and just executing: start http://script/location/clear_cache

CakePHP + NGINX + Memcache

I am trying to use Memcache on NGINX for CakePHP (2.4.7) but when I update the core.php & bootstrap.php to do this I am then thrown the following exception:
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured
I have tried to search if any other configuration is required but can't see anything. Any help would be appreciated
Thanks,
First of all you need be sure that your Memcached configured and working properly.
Check memcached port (11211 if default settings) / process etc... for example memcached -u www-data -vv.
Then if you using memcached default configurations you should change core.php configurations like following:
Uncomment section about memcached. After it it's should looks like this:
Cache::config('default', array(
'engine' => 'Memcache', //[required]
'duration' => 1800, //[optional]
'probability' => 100, //[optional]
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array(
'127.0.0.1:11211'),
'persistent' => true,
'compress' => false));
Now change $engine = 'File'; to $engine = 'Memcache';
Use caching for example in controller you need write data with key => value, then access that data with key. Example:
Cache::write($key, $value);
Cache::read($key);
That's all.
Hope it's help you.

An internal error has occured

I'm Vaijanath. I'm using cakephp installed on lamp. Now i have created a blog application, but when i run this on localhost/cakephpproject/cakephp/ it is showing an error:
"An Internal Error Has Occured".
And i had changed the "routes.php" in "/app/Config/routes.php" from
"Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));"
to
"Router::connect('/', array('controller' => 'posts', 'action' => 'index'));"
This is an internal error and i'm not able to solve it. Could you please help me in this?
Is your project in your user's public_html dir ?
If so, you must update the three .htaccess files, located in <projectBase>/, <projectBase>/app/ and <projectBase>/app/webroot, and add the following code after each RewriteEngine on statement :
RewriteBase /~<yourUserName>/<projectBase>/
Hope that helped.
In your CakePHP app in the ‘config’ folder change the following setting in the ‘core.php’ file
Configure::write(‘debug’, 0);
Change the ’0′ value to a ’2′ and CakePHP will print all debug errors.
It will display all the errors.. and when the functions works then again change it back to 0.

CakePhp Plugin: Problems with routing

Well, I am struggling for 2 hours trying to finding out how this not works.
The problem:
I have a plugin PaypalIpn in the Plugin Folder. The Plugin has a controller InstantPaymentNotificationsController and some actions inside.
If I try to access directly the plugin's controller with /paypal_ipn/instant_payment_notifications Cake says the there is no Paypal Controller.
Well, I added a route:
Router::connect('/paypal_ipn/:action/*', array( 'plugin' => 'paypal_ipn', 'controller' => 'instant_payment_notifications', 'action' => 'index'));
and surprise the webserver freezes and this errors is fired in httpd.log
PHP Fatal error: Allowed memory size of -2147483648 bytes exhausted (tried to allocate 320596 bytes) in libCake2.3/Cake/Error/ErrorHandler.php on line 114
According to plugin's installation notes the route should be:
Router::connect('/paypal_ipn/process',
array('plugin' => 'paypal_ipn',
'controller' => 'instant_payment_notifications',
'action' => 'process'
)
);
This is not what you have.
Also, be sure you have the latest version. The article on Bakery is from 2009 and is about a very old version.

Resources