Invisible Errors in PHP - php

Trying to figure out why a Wordpress site I moved is doing white screen of death.
Trying to turn on error dumping - but it isn't working. Absolutely nothing is showing up.
Here's sample code:
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
$con = mysql_connect('localhost', 'groupasa', 'groupasa');
$selected = mysql_select_db("groupasa",$con)
Echo "Test";
?>

for a fatal error you can turn on errors in php code you have to turn them on in apache or htaccess level. You could also go and look in the error log for the errors.

Right click and check the source of your page, sometimes the html doesn't show the error but it's actually in the code.
Not sure if this is the case but hope it helps.

Try putting the Echo statement at the very top of the page and then an exit; if the echo displays then your PHP compiler is working fine and you know that the issue is with the code on the page.
next, add the missing semicolon at the end of mysql_select_db line
you could also check your PHP error logs.

Most times you can solve the 'white screen' by going into the database and using the following query to forcibly 'deactivate' all active plugins.
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
The core of WP is pretty solid, but it's the plugins and garbage that really mucks everything up.

Related

Error reporting in PHP withi '.ini' files

So basically I have tried to setup an error reporting system that logs any PHP, HTML or any other error into a text file called 'errors.txt' located in a specific directory. However, the file is not being created.
Here is the code:
ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);
ini_set('log_errors',TRUE);
ini_set('error_log','/xampp/xampp-portable-win32-1.8.3-2-VC11/xampp/htdocs/EstateAgent/logs/errors.txt');
ini_set('display_errors',FALSE);
The errors are still be displayed to the user and they error log isn't being created inside of the directory specified.
I have also tried changing the standard values in my 'php.ini' file as suggested on other websites and I have still had no luck.
Any help would be greatly appreciated!
Thanks :)
For anyone who has similar problem - make sure you don't have any other error_reporting and ini_set in other files you use in your project. In those cases it may seem that error reporting is not working properly but in fact it this.
Try to change:
ini_set('log_errors',TRUE);
into
ini_set('log_errors','1');
and
ini_set('display_errors',FALSE);
into
ini_set('display_errors','0');
If it doesn't help, add at the very top beginning of your file:
<?php
error_reporting(0);
ini_set('display_errors','0');
echo $testVariable;
echo "Just testing";
?>
and check if any warning about this variable is displayed before "Just testing".
Now change above code into:
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
echo $testVariable;
echo "Just testing";
?>
and check if any warning about this variable id displayed before "Just testing".
As above 2 sample codes works as expacted, it's likely that those settings are change in other php files of user or php libraries used by user. You should scan your code and libraries code do track where changes are made and try to solve this issue either removing your code changing your desired reporting or commenting / setting properly (if there is such possibility in constructor or method) reporting in external library
You need to provide a fullpath for the 'error_log' property:
<?php
ini_set('error_log', 'c:/xampp/logs/php_error.log');
?>
You need to make sure that the following folder exists and is "writable": c:/xampp/logs/
If you're using Linux, then the fullpath will look like this: /xampp/logs/php_error.log
Also, use the following:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
ini_set('log_errors', '1');
?>

change error log output format: ini_set('error_append_string', 'string') and ini_set('error_prepend_string', 'string') does nothing

This is what I tell php to do:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', 1);
ini_set('error_log', 'errors.log');
ini_set('error_append_string', 'APP');
ini_set('error_prepend_string', 'PRE');
?>
Hoping that I would get all errors reported in one file, with "PRE" before the message and "APP" after the message. (My goal is to make PRE and APP into /n /r or something...)
But my error reporting log looks like this:
[14-May-2013 00:16:26] PHP Notice: Undefined variable:
nonexistentvariable in /home/www/dir/index.php on line 14[14-May-2013
00:16:28] PHP Notice: Undefined variable: nonexistentvariable in
/home/www/dir/index.php on line 14
No PRE, no APP...
How do I get it in there, so that my error reporting file will have each error on a newline, rather than a loooong string of errors that's not helpful to me?
EDIT:
So I noticed that with ini_set('display_errors', '1'); the "APP" and "PRE" strings are displayed on the page, in the error message.
That means I really need to find out where I can change the format for how php logs the errors. For example this whole timestamp thing - where is that specified?
EDIT:
It is not possible to change the way php logs errors, you have to make your own error handler.
ANSWER:
To truly achieve what I was going to, I asked a different question (to be more precise).
How to change the way PHP writes errors in the error log file?
As the documentation says nothing to that, I have tested your example. I realized that error_append/prepend_string only works for displayed but not logged errors
My goal is to make PRE and APP into /n /r or something...
You should use a regex for that. Should be possible, as every log messages starts with nearly same prefix. Will prepare one....
check phpinfo(); after ini_sets

Force Smarty to show PHP errors

I've been working with PHP for a while, but fairly new to Smarty.
I'm working with Prestashop and I've noticed Smarty seems to eat up all PHP errors - when there's an error in the PHP code, the .tpl file just outputs a blank page. I've been trying but I can't get Smarty to display whatever the PHP code outputs, even if there's an error.
PHP error reporting is set to show errors.
So, for instance, let's say this is the example.php file:
<?php
//included classes etc go here, irrelevant for this issue
error_reporting(E_ALL ^ E_NOTICE);
echo obvious wrong syntax"
?>
This file is connected to example.tpl which fits the output in a template block.
Obviously, it should throw an error. How do I make Smarty actually display that error?
To activate debug mode, go to config/config.inc.php
Find the following lines and chage off to on for the first one and set to true the second
/* Debug only */
#ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);
This will display PHP and SQL errors (this would probably be enough for you to resolve "blank page").
There is also a blog post on prestashop site about p() and d() methods and how to track exceptions
To activate templates debug in Prestashop version older than 1.5,go to config/smarty.config.inc.php
Find the following line and set it to true
$smarty->debugging = true;
When you refresh your page, themes/debug.tpl should be rendered.
To activate templates debug in Prestashop 1.5+ you can enable Smarty debugging via Admin panel
Preferences > Performance > Smarty
and set Always open console but console will be opened for everyone ( not good for live site :) )
or set Open console with URL parameter (SMARTY_DEBUG) and add ?SMARTY_DEBUG to the end of your URL to see console
Hope this helps.
I've seen #Sergei Guk's answer and off-course, it's a pretty good answer. However, prestashop has since released version 1.6.
So if you want to show all the errors in prestashop v 1.6.0.6, you just need to go config/defines.inc.php
Replace define('_PS_MODE_DEV_', false); with define('_PS_MODE_DEV_', true);
What it actually does is set a constant and in the next line it checks if "_PS_MODE_DEV_" is true then it will show all kinds of errors in prestashop
if (_PS_MODE_DEV_)
{
#ini_set('display_errors', 'on');
#error_reporting(E_ALL | E_STRICT);
define('_PS_DEBUG_SQL_', true);
}
else
{
#ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);
}
I have tested it and it works fine.
Set the $error_reporting variable.
See http://www.smarty.net/docsv2/en/variable.error.reporting.tpl

Wordpress untraceable white screen of death on migration

My problem was, after migrating a website to another server using backup buddy, I came upon a the white screen of death.
I turned on debug mode in Wordpress and still no errors, just white screen.
So I tried removing all the files and re uploading them again and leaving the database as is (the one imported by BackupBuddy) but it's still giving me white screen.
So I tried to trace the specific line where the white screen occurred and got stuck in a weird behavior.
In /wp-content/plugins/woocommerce/widgets/widget-init.php:
include_once('widget-cart.php');
include_once('widget-featured_products.php');
include_once('widget-layered_nav.php');
include_once('widget-price_filter.php');
include_once('widget-product_categories.php');
include_once('widget-product_search.php');
include_once('widget-product_tag_cloud.php');
include_once('widget-recent_products.php');
include_once('widget-top_rated_products.php');
When I add a "die('boom');" before
"include_once('widget-price_filter.php');" = boom is printed out.
When I add a "die('boom');" after
"include_once('widget-price_filter.php');" = boom is NOT printed
out.
So it's safe to say that the bug is inside widget-price_filter.php right?
The problem is when I add a die at the beginning of widget-price_filter.php, it does not print it out. It's like the line where the error occurred is nowhere.
What could be the cause for this?
So it's safe to say that the bug is inside widget-price_filter.php right?
Yes, totally (and you followed the correct way of debugging).
The problem is when I add a die at the beginning of widget-price_filter.php, it does not print it out. It's like the line where the error occurred is nowhere.
If (as you say you've done) you have added die('HELLO'); right at the top (after the <?php) and it does not appear - this means there is one of two problems
File not found
A syntax error in that page.
You can solve in 1 of three ways:
Check the php error logs (if you have access)
Before you call the "include_one" (in init.php) add:
error_reporting(E_ALL);
ini_set('display_errors', 'on');
Completely empty the code (just leaving the <?php die('HELLO'); ?>, check that appears and then add code in bit by bit.
If you got route 2, remember to take it out when you've got it working. Very important!
+1 for actually taking time to try to solve it yourself before posting (with the echo and die). So I hope that helps with the rest.

print_r return BLANK PAGE

I have a weird problem, I am using print_r($obj) in Joomla YOOtheme ZOO extension and it returns a blank page. it just act as die() !
it should output the object but it does not.
Please note that print_r() is working fine with some other objects and variables.
I am using XAMPP on Windows.
Any help?
Upon executing print_r() and var_dump(), the page is just blank, no error, view source shows:
<html>
<head></head>
<body></body>
</html>
Error reporting is turned on.
It is posible that $obj is too big to load, and grabs a lot of memory after which the script stops to work.
Thanks
Is error reporting turned on?
If not add to your code:
ini_set("display_errors", "1");
If it's outputting nothing, $obj contains nothing. Try var_dump() instead. Also, make sure you're seeing all errors that PHP is producing:
ini_set('display_errors', 1);
error_reporting(-1);

Categories