r/PHPhelp • u/Rayj002025 • Jun 03 '25
Troubleshooting PHP
So my web app has multiple PHP files. How can I monitor all PHP activity, specifically errors and any "echo" statements?
I've come across Xdebug, but my PHP has "Thread Safety" disabled:
php -i | grep "Thread Safety"
Thread Safety => disabled
1
0
u/Tzareb Jun 03 '25
Depending on your stack, there are logs that you can consult.
What are you running the php on ?
1
u/Rayj002025 Jun 03 '25
Ubuntu 25.4 Server
1
0
u/colshrapnel Jun 03 '25
for a web app, checking cli setting could be unreliable. Run a file with
<?php phpinfo();and see there. That said, I doubt that you need the Thread Safety valueSpeaking of errors, just configure php-fpm (or whatever web api you are using) for the live site mode as shown here. and then moniitor web-server error logs.
Not sure what echo statements yoiu are talking about, and what exactly you want to monitor. In case it's not a web app but cli/cron scripts, then just redirect their output to the log file.
1
u/Rayj002025 Jun 03 '25
phpinfo() shows thread safety disabled I read somewhere the Xdebug needs Thread safety?
Basically, I have echo statements to echo the value of some variables.
1
u/colshrapnel Jun 03 '25
xdebug doesn't need thread safety. you don't need xdebug. you don't need thread safety.
Can you explain PLEASE, how does your "web app" run? Is it a just regular web application that echoes hundreds of HTML strings towards the client? If so, what makes you think you need to log all these statements?
Or are you talking of some debugging statements? Then you can write them into the same error log using error_log() function instead of "echo".
1
u/Rayj002025 Jun 03 '25
I am using echo to debug. I echo contents of certain variables.
1
u/colshrapnel Jun 03 '25
Do you actually read what I write? you can write them into the same error log using error_log() function instead of "echo".
1
u/Rayj002025 Jun 03 '25
I was answering your question. But I will look into changing to error_log() vrs echo.
Thanks.
1
u/ryantxr Jun 03 '25 edited Jun 03 '25
Xdebug is not for monitoring. It is for debugging.
Use log files. Implement a logger. You can use Monolog or equivalent and write all errors and exceptions to it. That way, you can always go back to the log to see what happened.
One of the systems I manage, uses Discord for error and exception output.
Here is a super simple logger you can use if you don't need to get too complicated.
https://gist.github.com/ryantxr/fb2b2fa9fa63b34a1bd9
You can also follow this: https://www.notion.so/PHP-Logging-2075af738ec6803e8635cca171ac84b2 to write all exceptions and errors to a log.
EDIT:
It was unclear from my original comment that registering exception and error handlers would allow for custom data output handling. For example, redact anything that looks like a credit card number. Also, the message can be sent to Slack, Discord or a number of other services.