...

View Full Version : Logger Hanging Site



ArcticFox
01-24-2007, 08:07 AM
I've got a logging script that keeps hanging the site. When it's installed, the page takes forever to load. When removed, the page shows instantly.



<?php
$server = 'localhost'; // MySQL hostname
$username = 'username'; // MySQL username
$password = 'password'; // MySQL password
$dbname = 'dbname'; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName) = mysql_fetch_row(mysql_query($sql));



$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['HTTP_X_FORWARDED_FOR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName2) = mysql_fetch_row(mysql_query($sql));






$ti = date("l, F jS Y - g:ia");
$ip = getenv("REMOTE_ADDR");
$pr = getenv("HTTP_X_FORWARDED_FOR");
$ac = getenv("HTTP_ACCEPT");
$la = getenv("HTTP_ACCEPT_LANGUAGE");
$re = getenv("HTTP_REFERER");
$br = getenv("HTTP_USER_AGENT");
$se = getenv("SERVER_NAME");
$ho = gethostbyaddr(getenv("REMOTE_ADDR"));

$fp = fopen("./logs.php", "a+");

if (strstr($_SERVER["REMOTE_ADDR"], "127.0.0.0")) {
fputs($fp, "
<font style=color:#00cc00;font-variant:small-caps;font-size:14px;font-weight:bold;>AF - MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>Browser Type:</b> $br<br />
<b>WEBMASTER</b><br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}

else {
fputs($fp, "
<font style=color:#0099ff;font-variant:small-caps;font-size:14px;font-weight:bold;>MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>IP Address:</b> $ip - $countryName<br />
<b>Match Proxy:</b> <u>$pr</u> - $countryName2<br />
<b>HTTP Accept:</b> $ac<br />
<b>Languages:</b> $la<br />
<b>Referer URL:</b> <a target=_blank href=$re>$re</a><br/>
<b>Browser Type:</b> $br<br />
<b>Host Name:</b> $ho<br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}



if (strstr($_SERVER["HTTP_REFERER"], "codingforums")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "dynamicdrive")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "sitepoint")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}

if (strstr($_SERVER["REMOTE_ADDR"], "82.172.242.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.103.132.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "69.234.44.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "204.246.129.196")) {header("location: error403.php");}


?>




I don't know what's causing it. I took out the part that pulls from the db, but that had no effect. The logs.php page is nearly empty, so it's not like that's the issue.

Ideas?

aedrin
01-24-2007, 03:39 PM
Taking out the MySQL queries, I was able to run the code instantly.

Either your queries are not returning (taking a long time, or some other problem). Or it is an environment issue.

EDIT:

Have you tried putting in echo statements followed by a flush() to see where the script runs into a block?

ArcticFox
01-24-2007, 05:01 PM
Ah, hah! Thanks, Aedrin.

I did this:

$ti = date("l, F jS Y - g:ia");echo "date<br>";ob_flush();flush();
$ip = getenv("REMOTE_ADDR");echo "ip<br>";ob_flush();flush();
$pr = getenv("HTTP_X_FORWARDED_FOR");echo "pr<br>";ob_flush();flush();
$ac = getenv("HTTP_ACCEPT");echo "ac<br>";ob_flush();flush();
$la = getenv("HTTP_ACCEPT_LANGUAGE");echo "la<br>";ob_flush();flush();
$re = getenv("HTTP_REFERER");echo "re<br>";ob_flush();flush();
$br = getenv("HTTP_USER_AGENT");echo "br<br>";ob_flush();flush();
$se = getenv("SERVER_NAME");echo "se<br>";ob_flush();flush();
$ho = gethostbyaddr(getenv("REMOTE_ADDR"));echo "ho<br>";ob_flush();flush();

$fp = fopen("./logs.php", "a+");;echo "fopen1<br>";ob_flush();flush();


And find that this part $ho = gethostbyaddr(getenv("REMOTE_ADDR")); hangs it all up. It's not really needed, but any idea why it hangs?

aedrin
01-24-2007, 05:21 PM
It would be hard to say.

It is possible your host does not allow PHP to use DNS services.

ArcticFox
01-24-2007, 05:23 PM
I'm not sure, it's ithium.net

The value eventually shows up, but it just takes so long. Well, it's not needed so I'm yanking it out. :D

Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum