IIS PHP doesn't log errors to log file - php

My local windows webserver (IIS) doesn't log php errors to log file.The php53_errors.log file is always empty. http://prntscr.com/2aels How to fix it? I think something goes wrong with permission settings. But it shows errors on browser window. And, one more question:Notices like "Undefined index".. Are they really important?

In the IIS server manager tool, there is option call error page. Please disable to use the IE error page to show you the error.
Besides please go to the C:\inetpub\wwwroot\web.config this file controls how to display and log the error as well. It should have one line like this.
<httpErrors errorMode="Detailed" />

Do you have php.ini in right setup according to this?
http://php.net/manual/en/install.windows.manual.php
specially keys log_errors and error_log

Read the last part of your question:
Notices like "Undefined index".. Are they really important?
It depends on your definition of 'important'.
The easy answer is no, they're not important. That's the reason they're classified as notices rather than warnings. It's okay to ignore them.
However you should still pay attention to them, and try to fix them where possible.
For example, the notice you quoted "Undefined index". This is caused (as I'm sure you're aware) by referencing an array element that hasn't yet been defined.
It is best practice to prevent this notice from being raised by using isset(), because if you do that, then when you do still get the notice, you'll know it is important - maybe you made a typo in your variable name or array index? The code will still run, but it won't work properly, and getting the notice might be the first clue you have of that. If that notice is suppressed or drowned out by legitimate ones, you'll never spot it.
Most 'notices' raised by PHP are on a similar level to that -- they indicate that something might be wrong, but PHP doesn't know for sure. If you write your code defensively to prevent notices from being raised when you're happy with the code, then you can afford to pay more attention to the ones that do still crop up.
Hope that helps.

Related

How do I detect error in shared hosting/live server?

In localhost, we can easily find the errors like missing semicolon in line number xxx, undefined variable in line number xxx,class already declared etc. But, when I upload all my files in shared hosting and try to see results in the web browser, I get to see same error page everytime and it's really really hard to detect what exactly caused the error. The project which i uploaded to the live server was written in laravel. I have tried 'Display errors On' in php.ini, error_reporting(E_ALL). I have even checked the error_log in the root directory but, those logs are usually from few days ago. error image description here
Any possible solutions ? Or should I switch to server where proc_open is enabled?
Check this:
https://laravel.com/docs/7.x/errors
Laravel handles errors and can write them in a log file.
You can customize it if you want, but I don't think it's necessary to do so.
If you dont use any frameworks or ones that don't support such a feature for that matter you could always use the native PHP function set_error_handler and catch errors and write them in a log file.
Note: BEWARE of the excessive log file size. If your project has a lot of visitors or has lots of notices and warnings, this log files can get excessively massive, unreadable, and consuming your space. Don't turn it off, it's always good to know where are the errors, but check and debug them often and delete them when not needed.

Notice warning from PHP in Symfony uploading file

I have a form that allows upload three files at the same time but just one is required. That works fine, my only problem is the following: if I upload three files I haven't any problem but if I upload one or two files (leaving two or one files empties) I obtain the following notice:
Notice: No file uploaded in Unknown on line 0
As much as empty files. The files are uploaded properly without any other problem, but I want remove that notice... or unless hide it, although I prefer remove it. I tried to hide it using
error_reporting(0);
and
ini_set('display_errors',0);
but neither of two worked...
It is the first time that I have problem, if someone could lead me I'd be very grateful due to that I am stuck with it.
If you are having the same problem as me, check with phpinfo() if you are using a debug version of PHP. If you see that Debug Build has a value of yes, your problem will be fixed if you install a live version of PHP instead of a debug version
The Error itself is caused by running a Debug version of PHP 7, see the bug report. As noted by HPierce because it was a Debug build it overrides the usual PHP settings for error_reporting. However as the Original question is actually about how to hide certain [expected] error messages (Notices), my answer is to this detail specifically.
Kevin, the attempted ways to hide errors you've listed in your question would normally work on non-debug PHP builds. However, it is unwise to ignore the errors, rather than solving them at source. It's also (more) unwise to hide all errors simply due to having expected errors appearing.
As it's only a Notice, you can work around it by setting your error_reporting() value as below:
//report all errors except notices.
error_reporting(E_ALL & ~E_NOTICE);
I would suggest this is far wiser than turning off error reporting entirely which is not recommended. If you want to stop errors being output to browser (as referenced by Tina) you can use display_errors.
Perhaps you may also need to set
ini_set('error_reporting', 0);
depending on your php ini configuration?
Also make sure you set it before carrying out any of the code.

Suppress an error from the logs too

CodeIgniter 2.x still uses the classic mysql. We all know it's bad practice to still use it, but my job still requires me to use CodeIgniter.
I always have my Console.app (OSX) open watching my Apache/MySQL/PHP/CodeIgniter-native error logs.
Now I mostly have all notices/errors/etc. fixed always instantly when I see them and constantly monitor my development with Webgrind on my MAMP.
Back to the start; I constantly have one big annoying thing each page-load PHP always gives the error about mysql_pconnect is going to get deprecated in the future.
In the CodeIgniter driver the command is suppressed by # to not print the warnings to the screen, but it still ends up in my logs.
Is there any viable way to except one such error specifically in either PHP code or the PHP settings?
Locally I could recompile the whole PHP core and just remove the warning, but I would like to have the logs on our production installations rid of those warnings too :P.
Thanks in advance!
Traditionally, you can use set error verbosity using error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED) (i.e., report everything—except notices and deprecation warnings) as mentioned in "disabling deprecated errors".
Your issue may be related to CodeIgniter taking ownership of all errors.
system/core/CodeIgniter.php calls the function set_error_handler. You can find and modify the function _exception_handler it invokes on error in system/core/Common.php. It doesn't appear to be a configurable, so you may simply want to edit the line that begins with $is_error.

Suppressing PHP undefined variable messages?

When I developed a website on my localserver it was working fine.
Now that I've uploaded it live I'm getting several notices.
Notice: Undefined index: ... on line 14
I've figured out that it happens because I'm using variables which arn't defined, and would like to go through and fix it. But I need a live version working tonight.
Is it possible to suppress the Notices and have the website act as it does on my localhost while its on my live server?
You've got it twice wrong. On your localhost and on your live server!
Localhost
Always show everything on screen, you want to know about notices too before you go live, as you can see now!
Live server
Never show anything on screen, it makes you vulnerable (it's deadly)
Log everything, also notices! So don't do what the other answers tell you!
You can choose which kind of errors will show up on your site on a global scale through php.ini or through .htaccess for specific folders, or per script by using error_reporting().
Read more on that and which options to set for your specific needs at www.php.net/manual/en/function.error-reporting.php
Also read: http://www.php.net/error-reporting
Look in the file php.ini for a line similar to error_reporting = E_STRICT - Edit it to remove the STRICT bit and put in error_reporting = E_ERROR.
I would recommend that in the near future that you fix those errors anyway.

Annoyed with lack of debugging features in CodeIgniter. Am I doing something wrong?

I am doing a lot of development with CodeIgniter these days and I am extremely irriated with the lack of debugging features in CI.
It does throw errors if a view file is missing and so on. But when I forget to put a semicolon somewhere it simply does not throw any error.
I ensured now and again that error level is set to E_ALL, I checked the logs but nowhere the syntax errors are getting captured. This wastes a lot of my time.
I find that the best way to deal with this situation is to use an editor with PHP syntax checking. From the command line you can also run
php -l filename.php
to syntax check your file.
You can turn on syntax error reporting in your php.ini, but it is disabled by default.
set
display_errors on
along with your
error_reporting E_ALL
One alternative is to use an IDE like Eclipse in debug mode to step through the code. Once Eclipse is set up properly, it can step through trace points and display the status of each operation, line by line. It can be a real time saver.
If you have actual syntax errors in your PHP, I don't think there's any way for a PHP framework, such as CodeIgniter, to catch them.

Categories