Friend... you can do this way:
// Put your site IP bellow (you can ping your URL to get the IP)
$mySiteIp = '111.111.111.111'
//Get the visitor IP
$ip=$_SERVER['REMOTE_ADDR'];
//get the list of nodes that can achieve your site
$torList = file_get_contents("https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$mySiteIp&port=80");
//remove your IP address from the list. It is listed in the file header.
$torList = str_replace((string)$mySiteIp,"",$torList);
//check if the visitor IP is in the TOR list
if ((strpos((string)$torList, (string)$ip)) !== false)
{
banned();
}
Pulling the list from torproject.org on every hit is a Very Bad Idea, just grab it once a day and store a copy on the local filesystem.
I wouldn't worry about your own server's IP either. It's not ever going to be trying to hit itself.
In my faucet I'm storing/caching the result. But I think that consulting one time per day is less than the recommended.
TOR nodes are borning every hour...
Myabe check it every two hours could be a good move.