Why is the wordpress fatal error not being displayed? - php

Our site was migrated due to issues on our server providers end. It caused many errors and I fixed most of them. Now, for some pages, it just says there is an error. It display notices and a depreciated warning but I know this will not cause the entire page to stop working. Why is the fatal error not being displayed?
This is what I have tried.
define( 'WP_DEBUG_LOG', 'error.log' );
ini_set('display_errors','on');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
error_reporting(E_ALL);
Normally it would show a fatal error. I don't know why it isn't showing me the important error.
Please help!

First ensure that there is no place in your code where you set error_reporting to 0
e.g.
error_reporting(0);
as this will totally hide all error warnings and notices.
In php script, this three line of code will just turn it on
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
You should see the same messages in the PHP error log.
Other things that you will need to check
1.) PHP.INI Files or your Apache configurations
You can move to your php.ini files and ensure that the following parameters below are commented out and set on.
By commented out, I mean removing a semicolon**(;)** at back of it
Eg.
uncomented = ;display_errors=On
commented = display_errors=On // semicolon removed
display_errors=On
display_startup_errors=On
track_errors = On
html_errors=On
shutdown and restart apache for it to take effect.
2.) .HTACCESS Files
You can also check .htaccess files to see if any of these warning parameter flags are set to 0 which means off and set them to 1 which means On.
Remember to turn off all these error warnings in production.

Related

Not getting PHP errors?

For some reason on this particular script, which is a copy of a script I use in a lot of other places, I am not getting any PHP errors. It simply shows a blank page, and It took me a long long time to hunt down a missing semi-colon this morning. Why arn't errors showing up?
my PHP.INI for this sub-domain:
display_errors = On
short_open_tag = On
memory_limit = 32M
date.timezone = Europe/Paris
The code at the top of the page:
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
The Sub Domain is set to run PHP as an Apache Module Which is the same as every other domain I use.
So I am not sure why I am not getting errors displayed. Can anyone tell me?
EDIT:
This is solved, because the errors I was producing were on the page where I had got the lines:
error_reporting(E_ALL);
ini_set('display_errors', '1');
written. When I put the error on to a seperate page and included it, I could see the error fine.
I guess that's why they use bootstrapping!
You should set error_reporting to E_ALL in the php.ini as well: when a parse error occurs (such as a missing semicolon), your error_reporting(E_ALL) won't be used.
You could try to change this lines to get more information from php:
; The display of errors which occur during PHP's startup sequence are handled
; separately from display_errors. PHP's default behavior is to suppress those
; errors from clients. Turning the display of startup errors on can be useful in
; debugging configuration problems. But, it's strongly recommended that you
; leave this setting off on production servers.
display_startup_errors = On
; When PHP displays or logs an error, it has the capability of formatting the
; error message as HTML for easier reading. This directive controls whether
; the error message is formatted as HTML or not.
; Note: This directive is hardcoded to Off for the CLI SAPI
html_errors = On
error_reporting(E_ALL);
ini_set('display_errors',1);
ini_set('display_startup_errors',1);

error_reporting(E_ALL) does not produce an error

This is my PHP script -
<?php
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Which obviously should show something if it were to be executed.
All I see is an empty page. Why is error_reporting(E_ALL) not working?
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo('catch this -> ' ;. $thisdoesnotexist);
?>
Does not help either. All I get is an empty page.
I've been to php.ini and set display_errors = On and display_startup_errors = On. Nothing happens.
Your file has a syntax error, so your file was not interpreted, so settings were not changed and you have a blank page.
You can separate your file in two:
File index.php
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
include 'error.php';
File error.php
<?
echo('catch this -> ' ;. $thisdoesnotexist);
That error is a parse error. The parser is throwing it while going through the code, trying to understand it. No code is being executed yet in the parsing stage. Because of that it hasn't yet executed the error_reporting line, therefore the error reporting settings aren't changed yet.
You cannot change error reporting settings (or really, do anything) in a file with syntax errors.
In your php.ini file check for display_errors. I think it is off.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
In your php.ini file check for display_errors. If it is off, then make it on as below:
display_errors = On
It should display warnings/notices/errors.
Please read error_reporting int.
You can try to put this in your php.ini:
ini_set("display_errors", "1");
error_reporting(E_ALL);
In php.ini file also you can set error_reporting();.
Turn on display errors in your ini file:
display_errors string
Just do the following:
Check phpinfo();. Check if display_errors is on or off
If it is On, just add error_reporting(E_ALL); in your primary index file.
If it is Off, just add it in your primary index file
ini_set("display_errors", "1"); // This is the instant setup for individual applications
error_reporting(E_ALL);
then check phpinfo();. Check display_errors. Now it is on, which is only for this application
then create any code error for testing and reload the page
Hurray! Now you can see the errors in your console. If the errors are not displaying in your console and the page loading failed with a red alert in network, don't worry.
Check if you have enabled modsecurity and it has any rule checking is written in SecRule for PHP. Remove that secrule or disable the modsecurity for your development period.

How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

So, I don't really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.
ini_set('display_errors', 'On');
error_reporting(E_ALL);
NOTE: I don't have access to the php.ini file, as I'm using my school account's server.
So I introduced a bug (no semicolon after $buggy) like so at the top of my page:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$buggy
$x = 4 + 2;
...
However, I just get a Server error:
"The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly."
Any ideas?
EDIT:
I've reconfigured my code:
<?php
include_once 'database/errorSettings.php';
?>
<?php
$buggy // whoops
$x = 4 + 2;
...
errorSettings.php is the following:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
But it still doesn't work... wrong way to reconfigure?
What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.
Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.
You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.
Try this in a .htaccess file (assuming you can use one):
php_flag display_errors 1
php_value error_reporting 30719
I think 30719 corresponds to E_ALL but I may be wrong.
Edit Update: http://php.net/manual/en/errorfunc.constants.php
int error_reporting ([ int $level ] )
---
32767 E_ALL (integer)
All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
Adding to what deceze said above. This is a parse error, so in order to debug a parse error, create a new file in the root named debugSyntax.php. Put this in it:
<?php
/////// SYNTAX ERROR CHECK ////////////
error_reporting(E_ALL);
ini_set('display_errors','On');
//replace "pageToTest.php" with the file path that you want to test.
include('pageToTest.php');
?>
Run the debugSyntax.php page and it will display parse errors from the page that you chose to test.
Just write a following code on top of PHP file:
ini_set('display_errors','on');
Syntax errors is not checked easily in external servers, just runtime errors.
What I do? Just like you, I use
ini_set('display_errors', 'On');
error_reporting(E_ALL);
However, before run I check syntax errors in a PHP file using an online PHP syntax checker.
The best, IMHO is PHP Code Checker
I copy all the source code, paste inside the main box and click the Analyze button.
It is not the most practical method, but the 2 procedures are complementary and it solves the problem completely
I have had this problem when using PHP5.4 and Plesk 11.5
Somehow, the error reporting and display error settings in the Plesk domain configuration page were completely overriding any local settings in .htaccess or the PHP scripts. I have not found a way to prevent this happening, so use the Plesk settings to turn error reporting on and off.
You may have settings in your php.ini that prevents the local site from overriding these settings, perhaps enforced by the control panel used on your server.
To people using Codeigniter (i'm on C3):
The index.php file overwrite php.ini configuration, so on index.php file, line 68:
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
You can change this option to set what you need. Here's the complete list:
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
Hope it helps.

How to show code errors while running

previously i had php5.1 installed and i recently upgraded to php5.3.
In previous versions all syntax errors and other errors were display in page whenever error occurs and it was easy for me to debug.
But now whenever there is error in page it just stops processing and shows blank.
i tried adding following too:
error_reporting(E_ALL & E_STRICT);
ini_set('display_errors', 1);
at top of page but didn't work. Any suggestions?
Edit more info:
when i do phpinfo(), it shows my configuration file: c:\php\php.ini.
Further on opening and editing php.ini file i found:
error_reporting = E_ALL
display_errors = On
Edit More Info:
Corrected error_reporting to E_ALL | E_STRICT.
Found it almost blanks out whenever the error is being generated from code inside function or class.
try this.
ini_set('display_errors','On');
whenever there is error in page
What level of error? Is it fatal or not?
If fatal - then your in-code settings (error_reporting() and ini_set) are not used at all: php.ini ones are used instead.
IMO, you've provided insufficient info: at least php.ini values you have for error_reporting and error_log directives needed.

On the fly error reporting in PHP

When our site used to be on IIS hosting with PHP installed, I had error reporting set to E_NONE and was able to turn it on temporarily by using:
ini_set('display_errors', 1);
That command seems to no longer work now that we are on Linux/Apache hosting. I have tried purposely sending bad commands to the server and I get no errors reported.
What am I doing wrong? Is there any other way to temporarily turn on error reporting without having to edit the php.ini each time?
You can change error reporting to E_ALL using the following line:
error_reporting(E_ALL);
Try adding that to the file.
The best way to turn on all errors is:
error_reporting( -1 );
This is better than E_ALL, as E_ALL doesn't actually mean all errors in all versions of PHP (it only does in the most recent). -1 is the only way to ensure it's on in all cases.
I just had to do this in one of my scripts. DOMDocument warnings were killing my logs. So, here's what you do:
// First, grab a copy of the current error_reporting level
// while setting the new level, I set it to zero because I wanted
// it off - but you could easily turn it on here
$erlevel = error_reporting(0);
// Then, do stuff that generates errors/warnings
// Finally, set the reporting level to it's previous value
error_reporting($erlevel);

Categories