CakePHP 1.3 PHP Strict Warnings - php

I know there's a LOT of stuff written here about this but we're running a CakePHP 1.3 on the newest PHP version on our Debian server. Right now there's multiple people using the system and I just had to delete a 17GB error.log from the server. It keeps pushing PHP Strict Standards error messages to it even though I've supressed the messages from the CakePHP /cake/bootstrap.php by adding the ~E_STRICT and I've thought about adding this..
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
'trace' => true
));
.. to the /app/core.php but I'm afraid to go do it on a live operation.
Why cannot I suppress these messages from the bootstrap.php or is the core.php the only way even though the Configure::write('Error'), array()); is commented out in there?

Configure::write('log', E_WARNING);
This would log only warning and fatal errors. If you want to disable error logging, this should work:
Configure::write('log', false);

Related

Yii2 not catching fatal errors when error_reporting is set

When setting Yii2 to production mode in index.php -
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod')
I have a logger, which correctly logs errors while in production mode, and prints out an appropriate error message on user page, but also show these error messages on notices (killing pages unnecessarily).
So, I set error_reporting in index.php -
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
But this prevents Yii2 from catching errors at all, so that they don't get logged, and renders a blank page in the event of any error allowed by error_reporting. It prevents notices from killing the page, but logging quits working when I use error_reporting()
Is there a Yii2 appropriate way of doing this? Has anyone had this issue before? Thanks for all attempted solutions.
The error log configuration -
$log['targets'][] = [
'class' => 'understeam\slack\LogTarget',
'exportInterval' => 1,
'levels' => ['error', 'warning'],
'except' => [
'yii\i18n*',
'yii\web\HttpException:404',
'yii\web\HttpException:403',
'yii\web\ForbiddenHttpException',
'yii\web\NotAcceptableHttpException',
'yii\base\InvalidRouteException'
],
];
The above is using the vendor package "understeam/yii2-slack": "~0.3"
It was interesting case for me, and I had similar problem, and I think there is no way to solve this with internal Yii2 ErrorHandler. So I decided to create a package with extended ErrorHandler that I hope can solve your issue.
Install it:
php composer.phar require cronfy/yii2-web-errorhandler
Set error reporting to report all errors:
error_reporting(E_ALL);
Configure error handler component in yii config:
'components' => [
'errorHandler' => [
'class' => 'cronfy\yii\web\ErrorHandler',
'typesToExceptions' => YII_DEBUG ? E_ALL : false,
'typesToLog' => E_ALL,
],
// ... other components
],
With this configuration:
In DEBUG mode all errors will be logged AND converted to exceptions.
In PRODUCTION mode all errors will be logged too, but will NOT provide exceptions that would break page.

Turn off notices in cakePHP

I am new with cakePHP. I facing issue with notice on live server. I want to suppress or turn off these notices. I have tried adding,
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
in the index.php file in main folder. Also added same in bootstrap.php file but no luck. Can anybody suggest me how I can do this.
You can disable the debug feature by turning debug to 0 in the app\Config\core.php file
Configure::write('debug', 0);
If still you get the same issue so please check your live server Php version and also check the same on development server, I think there is php version compatibility issue so please see
link http://bakery.cakephp.org/articles/markstory/2013/07/05/cakephp_2_3_7_2_4_0-beta_released
Hope it should work for you.
In the core.php file in /app/config, find this line and edit the level of errors you want to show:
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
You may now add or remove the error levels as given on this page: http://php.net/manual/en/function.error-reporting.php
Open config/core.php
0: No error messages, errors, or warnings shown. Flash messages redirect.
*
Development Mode:
1: Errors and warnings shown, model caches refreshed, flash messages halted.
2: As in 1, but also with full debug messages and SQL output.
seach this
Configure::write('debug', 0);
You are getting warnings and notice just because your DEBUG is TRUE. to solve this probem.
Go to config/app.php and just change true to false as done below..
Find this line
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),
And change above line to
'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),
Try this in config/app.php file:
'Error' => [
'errorLevel' => E_ALL & ~E_USER_DEPRECATED & ~E_NOTICE & ~E_WARNING,
......
......
],

PHP - Strict Standards error with 5.4.?

I (like a lot of others) am seeing Strict Standards errors with PHP 5.4.???.
Strict Standards: Only variables should be passed by reference in /home/xxxxxx/public_html/xxxxxx/init.php on line 64
There must have been a change between 5.3 and 5.4. All the "wisdom" on the Internet seems to be about turning the error messages off. In this case this is a program (1,000's of lines written by someone else) that I am disinclined to try to resolve.
If I turn off the error reporting then the script does not execute.
I am trying to work the issue with the writer of the script.
Is there any other solution? Is there a setting that can be placed in the .htaccess file that will allow "non strict standards"?
You need to go into your php.ini file and assign the following:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
This will allow you to show all warnings except deprecated & non-strict standards.
If you want to fix the error rather than ignore it (recomended):
$uri = explode("/",$_SERVER['REQUEST_URI']);
define("INSTALL_URL" , $protocall.$host_name . str_replace("/".array_pop($uri),"/",$_SERVER['RE‌​QUEST_URI']));

Static Standards error after updating to php 5.4.9

I am getting following errors after updating php to version 5.4
Strict Standards: Non-static method Debugger::invoke() should not be called statically, assuming $this from incompatible context in /usr/share/php/cake/libs/debugger.php on line 575
Strict Standards: Non-static method Debugger::getInstance() should not be called statically, assuming $this from incompatible context in /usr/share/php/cake/libs/debugger.php on line 575
I have already tried following solutions
Error while Disabling error reporting in CakePHP
Cakephp doesn't work after installing php5-curl package (Unable to locate "Cake" folder as I have baked my project)
Wampserver cakephp 1.3 Strict standards error
How to eliminate php5 Strict standards errors?
PHP 5 disable strict standards error
https://stackoverflow.com/questions/11799085/turn-off-php-strict-standards?lq=1 (Was not able to turn off the errors)
Cleared cake cache, web browser cache, cookies and restarted server after each change. Even tried in private browsing and chrome, firefox, ie also.
I believe this is because this app is built on an older version of CakePHP, which may use some deprecated functions.
It'd be awesome if you (or someone else) could upgrade Cake to a new stable branch.
As of now try this in your core.php you could remove the E_STRICT from your error reporting:
i.e go to app/Config/core.php find
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
replace it as
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_STRICT & ~E_DEPRECATED,
'trace' => true
));
Changing the error_reporting function does work to fix this. However, cakephp seems to set these flags in several places, that's why the solution may not have worked for you (I went through the same)
Do a source-wide search for "error_reporting" and you'll find it used in several files. Add the flag "~E_STRICT" wherever you can. For instance:
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
You'll see it in places like /cake/bootstrap.php, /cake/libs/configure.php, /cake/console/cake.php, etc. I just changed them all to exclude E_STRICT and the problem was fixed.

MongoDB Codeigniter

I managed to run MongoDB on Codeigniter using Alex Bilbie` library. The operations go well (connection, queries etc. ) but sometimes I get these PHP notices:
Message: Mongo::__construct() [mongo.--construct]: localhost:27017: pool get (0x4bfab20)
Filename: libraries/Mongo_db.php
Line Number: 1274
A PHP Error was encountered
Severity: Notice
Message: Mongo::__construct() [mongo.--construct]: localhost:27017: found in pool (0x4bfab20)
Filename: libraries/Mongo_db.php
Is there a way to get rid of these? or maybe hide them..as they don't seem to mess up my pages in another way than splashing into the user's screen.
EDIT
On a few pages though, I use the JQgrid and when the errors show up they mess up my HTTP response and render some messy data.
The specific notice messages here have been removed in the MongoDB PHP driver 1.2.11 or later (see PHP-431). Upgrading your MongoDB driver to the latest should remove the excessive notice logging.
General notes on proper settings for Code Igniter logging in production still apply...
The E_NOTICE level of error reporting is intended to warn you about possible bugs or typos. It is typically only used as a development setting rather than for production messages.
The default error_reporting setting in PHP4 and PHP5 is actually set to ignore these:
E_ALL & ~E_NOTICE
The Code Igniter index.php has an application environment setting which normally shows all errors for development and suppresses error reporting for testing and production. You should set this appropriately:
define('ENVIRONMENT', 'production');
If you actually want to capture these messages for a production environment you should update the production settings in your index.php so that instead of error_reporting(0) you have:
error_reporting() set to appropriate level of detail
display_errors off
log_errors on
error_log path set
For example, in index.php you could have:
case 'production':
error_reporting(E_ALL);
ini_set('display_errors','Off');
ini_set('log_errors','On');
ini_set('error_log','/var/log/php5.log');
break;
That way the messages/notices will still be saved to the error_log if you want to review them, but they will not be shown to the end user.
Off the top of my head, there are a few things you could do. This is not an answer regarding a fix to the MongoDB error you are receveing, but rather regarding some methods in which you could hide the errors.
a) Use the '#' operator to ignore any error outputs from the method being called in which outputs the errors you are receiving. This would result in you renaming the method call to the following #method_outputting_mongodb_error($foo,$bar);.
b) Turn off error reporting in CodeIgniter. This is not the best method as all other errors will not be outputted.
There is a good link here re: how you can turn off error reporting: http://phpdog.blogspot.fr/2012/02/codeigniter-error-reporting-handling.html
As #Stennie mentions this has been fixed in later versions of the driver: https://jira.mongodb.org/browse/PHP-431
Try and upgrade.
Also this only existed on the Windows driver and only start happening after v1.2.1. I know that because the guy who made that JIRA also tried 1.2.1 on my advice and he didn't get those E_NOTICEs. I remember having the conversation that actually triggered that JIRA now :).
Unlike others I don't think you should "hide" these errors with E_ALL & ~E_NOTICE. No one is quite decided on hiding E_NOTICE however the general concensus is that it is not the best thing. Of course you would not want your logs to be filled with all this debug info about the MongoDB extension, instead the MongoDB extension should be silent (as you think it should).
Another reason I would not hide E_NOTICE is because of the php.ini of later versions of PHP:
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
By default PHP will actually install for Production Value (as it does for me) as such the default for PHP error reporting is:
E_ALL & ~E_DEPRECATED
This is the value I have for error_reporting on both my AWS and my local Ubuntu server 12.04 and I have not changed the values since installing as such the default value I gain from installing PHP from both repo and source is:
error_reporting = E_ALL & ~E_DEPRECATED
So the recommended default setup for production for later PHP versions (and probably future ones) actually shows E_NOTICE, which is useful but not if the logs are being filled with stuff from the Mongo extension.
Edit: Downvoter care to explain? I have basically given the same answer as #Stennie, why the downvote?
I have edited my answer to actually take the conversation in the comments on this answer and #Stennie's answer into consideration so the answer makes more sense now.

Categories