• Resolved davidkoh83

    (@davidkoh83)


    Dear sir,

    Firstly, thank you for your plugin. It is very good at what it does. My client uses it a lot and they have a lot of IP addresses in it. However, recently we found that the website has slowed down significantly. I narrowed down the problem to your plugin. The website sped up a lot when I had it disabled.
    Through my investigation, here are my findings:

    Using Query Monitor, I had several notices that states:
    Undefined offset at
    wp-content/plugins/ip-based-login/lib/IPv6/BigInteger.php:893
    wp-content/plugins/ip-based-login/lib/IPv6/BigInteger.php:896

    I cleared the list of IP addresses and added them in bulk instead. It seems that certain IP addresses are not calculated correctly. Here are some of them
    4.31.46.6
    4.31.46.7
    4.31.46.8

    I printed out to screen the value of $i and $value at the location the problem occured. Inside your loop, they were looking at:
    $value = Array( [0] => 2043398 [2] => 0)
    $i = 1
    So there is no index 1 that spout the error out.

    I hope this will help you to come up with a fix soon. Thank you

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter davidkoh83

    (@davidkoh83)

    In addition to the above, when there are more than 600 entries in the database, the website will slow down significantly and causes timeout. You can simulate this at loader.io serving 100 visitors in 1 minute using a high end server

    Thread Starter davidkoh83

    (@davidkoh83)

    To improve your plugin’s performance, I got it to ignore checking if a person is already logged in. On top of that, for those who are not logged in, I created a session which will expire in 1 hour before checking again. This doubled the page load speed

    Plugin Author brijeshk89

    (@brijeshk89)

    Hi David,

    Thank you for taking time to find the causes of the slowness and the undefined index notice.

    I will work on both the things and fix the same soon.

    Thread Starter davidkoh83

    (@davidkoh83)

    Hi Brijeshk89,

    I identified that this chunk of code:
    $query = "SELECT * FROM ".$wpdb->prefix."ip_based_login WHEREstatus` = 1″; David – 13/04/2021
    $ip_ranges = ipbl_selectquery($query, 1);
    if(!empty($ip_ranges) && is_array($ip_ranges)){
    foreach($ip_ranges as $k => $v){
    // Is the IP in the blacklist ?
    if(inet_ptoi($v[‘start’]) <= inet_ptoi($logged_ip) && inet_ptoi($logged_ip) <= inet_ptoi($v[‘end’])){
    $username = $v[‘username’];
    break;
    }
    // Is it in a wider range ?
    if(inet_ptoi($v[‘start’]) >= 0 && inet_ptoi($v[‘end’]) < 0){
    // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
    // if the current IP is <= than the start of the range, it is within the range
    // OR
    // if the current IP is <= than the end of the range, it is within the range
    if(inet_ptoi($v[‘start’]) <= inet_ptoi($logged_ip)
    || inet_ptoi($logged_ip) <= inet_ptoi($v[‘end’])){
    $username = $v[‘username’];
    break;
    }
    }
    }
    }`
    causes the website to load very slowly. With more than 1200 records, this loop really slow things down with moderate traffic. It seem to me that the function inet_ptoi runs a bit slowly and you have it calculate the user’s logged in IP multiple times in every loop on top of the IPs from the database. In addition, this function is called on every page visit. Therefore, the time it takes is roughly like visitor * page visits * db records which is a lot of calls and causes the CPU to hit 100%.

    I commented out the chunk of code and use:

    $myip = inet_ptoi($logged_ip);
    	$query = "SELECT * FROM ".$wpdb->prefix."ip_based_login WHERE <code>status</code> = 1 AND INET_ATON ( start ) <= ".$myip." and INET_ATON ( end ) >= ".$myip;
    	$ip_check = ipbl_selectquery($query, 1);
    	if(!empty($ip_check) && is_array($ip_check)){
    		$username = $ip_check[0]['username'];
    	}

    This runs a lot faster as I get the database to find the IP instead and return only 1 record. Thanks

    Thread Starter davidkoh83

    (@davidkoh83)

    I just found out a huge problem with 1 of your main function inet_ptoi. It calculates certain IP Addresses wrongly which is a major issue for your plugin.

    We maintained an IP Address range of 128.6.0.0 to 128.6.255.255.
    1 of our user was accessing via 128.6.37.84. Your function inet_ptoi translates this to 2080777556 which is wrong. If you use an online IP to integer converter, you will get 2147886420.

    If you use SELECT INET_ATON(start), INET_ATON(end) FROM wp_ip_based_login in the database, you will see the range is 2147876864 to 2147942399 (128.6.0.0 to 128.6.255.255)

    Plugin Author brijeshk89

    (@brijeshk89)

    Hi,

    Extremely sorry for the delay in resolving the issues.

    I have reviewed your suggestions, made some changes and just released v2.0.4 which should resolve all above mentioned issues.

    Can you please test and let us know if you still face the issue with the latest version ?

    Thank you for reporting the issues and helping to improve performance of the plugin.

    Plugin Author brijeshk89

    (@brijeshk89)

    Hi,

    We did not receive your confirmation that the new version resolved the issue.

    We assume the issue was resolved and will mark this thread as resolved.

    If that is not the case and you still see the issue feel free to re-open this thread.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Bug found. Causes whole website to slow down significantly’ is closed to new replies.