-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for high CPU usage caused by "PHP Warning" flooding the journal. #69
Conversation
PHP Warning: fgets() expects parameter 1 to be resource, boolean was given
Thanks for the submission! One of us will give this a look over and hopefully include it! |
@@ -156,11 +156,12 @@ function readInBlockList() { | |||
$file="/etc/pihole/gravity.list"; | |||
$linecount = 0; | |||
$handle = fopen($file, "r"); | |||
while(!feof($handle)){ | |||
if(gettype($handle) == "resource") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fopen returns false on error, or a resource on success. seems like if ($handle !== false)
would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will test this out later on today.
The fopen
section was something I hacked together from various stack exchange answers (I'm not a PHP developer :smile), but it was the fastest way of reading gravity.list
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fopen code is fine, but it would actually be faster to call wc -l
on the file through an exec().
I am more concerned about the efficiency of calling gettype, especially for resources when a simple boolean check would do
may have figured out a better way that is fast and memory friendly, ill attempt to update the pull request but im a little new to git lol |
to update the PR all you need to do is push commits to your I don't remember why I ended up doing the line count that way...! Actually, i was mistaken earlier. The part where speed was extremely important, is this bit, which is where we check each name on the dns log to see if it is in gravity. |
how's that? I tested it it on that 34MB hosts file from XDA seems to work. |
I'll give it a test when I get home tonight. I'm at work currently! |
Ah, forgotten about this! Will test now.... |
Looks good, and it doesn't appear to break the count, will merge into devel. Thanks! |
This should fix the journal flooding causing high CPU usage
@pi-hole/dashboard
PHP Warning: fgets() expects parameter 1 to be resource, boolean was given