Forum Moderators: open

Message Too Old, No Replies

Need for speed with MySQL

         

hdpt00

3:56 am on Jan 31, 2006 (gmt 0)



If I have a list of IPs in a MySQL that I want to not display certain content (AdSense ads), what would be the fastest way to do that? Put them in a text file via a cron job and check if it contains the IP, do a MySQL look up every time a page is loaded and index the IP column or what?

I'm going to need whatever I do to display on every page, or possible just store a session or something, but there will need to be some type of lookup.

Thanks for any advice.

Romeo

2:57 pm on Jan 31, 2006 (gmt 0)

10+ Year Member



it depends on your data.

If there is a static list of just a few records (< 100), a flat file should do, which the application would read thru on every request. Modern operating systems do disk I/O cacheing, so a small file should stay in memory and access should be fast.

If you already have the data in a database, then use it. Lookup on an indexed column is fast even for more data.

You could try both and take timestamps before and after getting a hit or a miss and look at the results to judge about the performance impact of either solution.

Regards,
R.

Frank_Rizzo

3:19 pm on Jan 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As Romeo says it depends on the size of the look up list.

One other issue could be manageability - how often is the look up list updated, who does it etc?

---

For the the fastest way to do this I would suggest not using a database at all but using plain php code and a string variable to check against.

***************************
* lookup.php
*
* Fill $lookup_list with a list of ip's which you want to check for
*
*

$loookup_list = "123.123.123.123 100.100.100.100 222.222.222.222 111.111.111.111";
$ip = $_SERVER["HTTP_CLIENT_IP"];
if (preg_match("/$ip/", $lookup_list)) {
$ip_found = 1;
} else {
$ip_found = -1;
}

Then at the top of each page you would have:

require_once('lookup.php');

and somewhere in your page you would have:

if $ip_found = 1 {
echo "IP matched so display something else";
} else {
echo "Display Adsense stuff here";
}

hdpt00

9:00 pm on Jan 31, 2006 (gmt 0)



I decided to do a lookup such as valid_user(), then if there is a $_SESSION['valid']=="1" then they are valid and vice cersa. If no $_SESSION found it does the database look up then sets the sessions.

Working pretty good for now.