Skip to content
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

Merged
merged 3 commits into from
Apr 15, 2016

Conversation

7h3ju57
Copy link
Contributor

@7h3ju57 7h3ju57 commented Apr 5, 2016

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

PHP Warning:  fgets() expects parameter 1 to be resource, boolean was given
@PromoFaux
Copy link
Member

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") {

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

Copy link
Member

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!

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

@7h3ju57
Copy link
Contributor Author

7h3ju57 commented Apr 6, 2016

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

@PromoFaux
Copy link
Member

to update the PR all you need to do is push commits to your 7h3ju57:devel branch!

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.

@7h3ju57
Copy link
Contributor Author

7h3ju57 commented Apr 6, 2016

how's that? I tested it it on that 34MB hosts file from XDA seems to work.

@PromoFaux
Copy link
Member

I'll give it a test when I get home tonight. I'm at work currently!

@PromoFaux
Copy link
Member

Ah, forgotten about this! Will test now....

@PromoFaux
Copy link
Member

Looks good, and it doesn't appear to break the count, will merge into devel. Thanks!

@PromoFaux PromoFaux merged commit 4cbebe6 into pi-hole:devel Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants