Duplicate entries in PHP error_log using set_exception_handler - php

I cannot seem to locate the source of this issue. I actually have nearly the same Docker container and Exception handler lib running in another app. However, for some reason, I'm getting duplicate log entries in the error log file.
The issue is that it's not just duplicate entries that are the same (that'd be another interesting issue). It's the same Exception being logged and the same stack trace, but one is from my custom Exception handler (JSON), and the other is the default PHP error log handler (or so it seems - tested with CLI SAPI as well as PHP-FPM).
I was under the assumption that PHP wouldn't write to the log file if an exception handler was set. I'm also executing die(1) at the end of the callback function for the Exception handler.
Again, all of the Exception handling code seems to be working well. It's just that PHP is still logging the Exception. Is there a setting or something else that I'm missing here needing to be done on the PHP config side?
Below is a copy of the error log output:
[24-Nov-2018 02:20:11 UTC] PHP Exception: Testing in /srv/www/boot/common.php on line 65
[24-Nov-2018 02:20:11 UTC] PHP Stack trace:
[24-Nov-2018 02:20:11 UTC] PHP 1. {main}() /srv/www/public/index.php:0
[24-Nov-2018 02:20:11 UTC] PHP 2. require() /srv/www/public/index.php:13
{"timestamp":"2018-11-24 02:20:11 UTC","level":"critical","message":"Testing","app_version":{},"environment":"dev","class":"Exception","file":"\/srv\/www\/boot\/common.php","line":65,"code":0,"previous":null,"trace":[{"file":"\/srv\/www\/public\/index.php","line":13,"function":"require"}],"user":[],"tags":[],"extra":[],"output_buffers":[]}

Going to leave this here for anyone that might come across this. The issue turned out to be XDebug which hijacks your Exceptions. It was enabled on this particular app in our dev env.

Related

How to attach stack trace to error log messages in PHP?

I run multiple WordPress sites which have multiple themes and plugins from multiple different authors. I always check my error log and try to contact the authors to fix bugs in their code, but a lot of them are logged as something like:
PHP Deprecated: wpmu_new_blog is <strong>deprecated</strong> since version 5.1.0! Use wp_insert_site instead. in /wp-includes/functions.php on line 5148
PHP Warning: array_merge(): Argument #3 is not an array in /wp-includes/class-wp-customize-widgets.php on line 376
PHP Warning: Error while sending QUERY packet. PID=23688 in /wp-includes/wp-db.php on line 2033
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /wp-includes/wp-db.php on line 1635
As you can see, the warnings occurred in files inside wp-include, which are available to all plugin/theme/core authors, so there is no way for me to find out who called the deprecated function, passed the wrong function parameters or whatever they did.
I also cannot easily reproduce the error in a dev environment because I don't know what action triggered it.
Everything would be much easier if I could change some PHP (or even server) setting that would cause a stack trace to be appended to each error log message.
This is one of those things that, as common as my problem probably is, Google is unhelpful because all search results try to explain how to append the stack trace to my own code, not to anyone's code.
You could install the Xdebug extension to PHP, which overrides the error logging mechanism of PHP and adds stack traces to errors, warnings, etc. when enabled. See Xdebug documentation.

PHP errors in Nginx error log instead of Monolog log files

I'm getting a following error in my application:
2018/08/31 06:13:24 [error] 20208#20208: *139993 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function setTime() on boolean in /var/www/website.com/releases/20180829221434Z/src/Somenamespace/SomeClass.php:218
Of course, I understand that this is a problem in my code and I have to fix it, but what bothers me is that this exception is not caught and logged by Monolog, but instead it ends up in Nginx log.
My questions are:
1. Is is even possible that Monolog catches and logs this kind of error?
2. If the first one is positive, is there any particular configuration in PHP (7.0.18) of Symfony (3.4) that should be applied for my application?

Disable Xdebugstack trace in apache error.log without disabling Xdebug

I recently installed xdebug, and now stack traces are printed to my apache error.log:
PHP Fatal error: Call to a member function get_upload() on null in /var/www/html/template/user/post-single.php on line 10
PHP Stack trace:
PHP 1. {main}() /var/www/html/index.php:0
PHP 2. include() /var/www/html/index.php:19
I dont like them, as they clutter my log, and if i need them i will get them from my debugging client. Is there any way i can disable them?
EDIT: To be clear, i do not want to disable Xdebug, I just want it to not print the stack traces.

Why is this error happening? Class 'FPDF' not found -- typo3-flow

The error happens when warming up caches and is in full:
PHP Fatal error: Class 'FPDF' not found in /home/shop/public_html/releases/20150122171219/Packages/Sites/Mystuff.ModelSite/Classes/Mystuff/ModelSite/Service/InvoiceService.php on line 14
Uncaught Exception
Execution of subprocess failed with exit code 255 without any further
output. (Please check your PHP error log for possible Fatal errors)
More Information
Exception code #1355480641
File /home/shop/public_html/releases/20150122171219/Packages/Framework/TYPO3.Flow/Classes/TYPO3/Flow/Core/Booting/Scripts.php line 531
Exception reference #201504011936306ce58c
I've seen this error before and got around it but can't for the life of me remember how nor can I find the notes I'm sure I made about it. Driving me crazy. What is weird is that the live server gets this error but not my dev server, which is a copy of the live one. The fpdf.php is there.
Thanks

why is new SimpleXMLElement($tags) causing my php script to crash;

I am trying to run some client code to call a server side API.
I put various put statements to see where the code crashes and the line crashing it is
$tagXml = new SimpleXMLElement($tags);
(where tags is the result of a file_get_contents call)
I downloaded php5 and I am running it from the php source file from the command line.
Why is this crashing the code.
Perhaps there is an addon for php I need to add to use new SimpleXMLElement($param)
edit I got error reporting working
Warning: simplexml_load_file(): I/O warning : failed to load external entity "https://api.domain/v2/andy/tags" in C:\java\domain-api-v2\simple\list-
tags.php on line 30
working line 30
Fatal error: Uncaught exception 'Exception' with message 'String could not be pa
rsed as XML' in C:\java\domain-api-v2\simple\list-tags.php:37
Stack trace:
0 C:\java\domain-api-v2\simple\list-tags.php(37): SimpleXMLElement->__const
ruct('')
1 {main}
thrown in C:\java\domain-api-v2\simple\list-tags.php on line 37
I would check your error log. There are two immediate possibilities:
You are not including the SimpleXMLElement class in the file that you are running
$tags is some kind of format that SimpleXMLElement doesn't like.
If you check your error log (and have error reporting turned on) then you should see whats going on.
I was experienced this problem before. How much size of $tags contents ?
You have to use simplexml_load_file() instead of file_get_contents() , if file's size are bigger and server performance is low.

Categories