Jump to content

Recommended Posts

I've been through this a hundred times. I cannot make php display errors consistently.
My php.ini file has this:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On

Nothing exists below these params that would change them.

I have a file https://dev.aecperformance.com/php_info.php  which shows my php info.
When I pull that up I see:
Loaded Configuration File /etc/php/8.1/apache2/php.ini

I don't understand why this is. It used to be in /etc/php/8.1/fpm
php8.1-fpm is installed and is active.
Whether or not php is actually using it I can't say. It should be using fpm.

Nevertheless, I have uploaded the php.ini file to both:
/etc/php/8.1/apache2/php.ini and to /etc/php/8.1/fpm/php.ini

I've rebooted the server since making the changes to make sure that php is reloaded.

On my web page I have:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

STILL when I try to load the page I get: This page isn’t working
https://dev.aecperformance.com/test.php
 

How can I make PHP display errors and suppress warnings?

56 minutes ago, SLSCoder said:

On my web page I have:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

If you have the settings that you want in the ini file, why override them with E_ALL in your webpage?

Just based on the title of this thread:

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT

Do you understand what the & and ~ do here, in terms of bitwise operations?  Hopefully you understand that this starts with everything, and suppresses notices, deprecation messages and "strict" checking.

Warnings are covered by E_WARNING.  So if you truly want to suppress warnings, then you should have:

error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT 

Changing settings in a script doesn't always work, depending on the type of error in your code, and to Barand's point, doesn't make sense in most cases, when you can just make settings what you want them to be in the .ini.   

8 minutes ago, Barand said:

I would recommend that, while developing, you should use E_ALL with no suppression of the other levels.

I agree.  There might come a time when you have problems you can't fix with a reasonable amount of effort, particularly if those problems are in libraries where you can't upgrade, but for anything new, you should just fix the issues, or as many as you can.  Turning all the messaging off means you won't even know about many of the things that should be addressed.

I added the code in the page because it still would not display the errors. I wasn't confident that I had the 'right' php.ini file even though I did edit the one shown in php_info.php.
Normally, that code wouldn't be there.

I'm aware that & ~E_NOTICE turns off notices.

My problem was that even if I have php.ini set as: error_reporting = E_ALL the page still wouldn't show the parse error.
The error was caused by a missing semi colon and yesterday the page returned: This page isn’t working

Today the error displays as it should. I've removed the error display code on the page and it still works fine.
I *swear* I didn't change anything. Yesterday when I quit, it didn't work. Today, it works just fine. ?#)!@#$???

It's all good now.

You guys are a lot of help. We appreciate you.
Thanks


 

On 3/23/2022 at 2:53 PM, SLSCoder said:

Whether or not php is actually using it I can't say. It should be using fpm.

It's not, for what it's worth.  You can tell by looking at the Server API: line in the phpinfo() output.  Yours says:

Server API 	Apache 2.0 Handler 

If you were using FPM, it would says

Server API 	FPM/FastCGI 

So if you want to use FPM you need to adjust your configuration for apache to do so.  If you don't really care, then just make sure you edit appropriate php configuration file.

On 3/23/2022 at 2:53 PM, SLSCoder said:

On my web page I have:

Having code in the page won't help with issues that prevent the page from running in the first place such as your syntax errors.  For that the settings must be configured in the php.ini file.  After making changes in the php.ini file, you need to reload the configuration by reloading/restarting the apache service.

Edited by kicken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.