?

Log in

No account? Create an account
June 24th, 2008 - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2008-06-24 16:01
  Subject:   In which I show some PHP that I consider braggable.
Public

I recently did some PHP work that I think isn't entirely shabby.

This is the dashboard page to see which of our bonded senders are allowing their IP addresses to go onto the various anti-spam DNS blacklists:

2.8 MB imageCollapse )

The Critical/Significant/Informational columns are completely dynamic. You can go into the db and add a row or alter a row to add or alter a blacklist, and the web page will restructure itself accordingly the next time you load it. On the left are the top 100 "worst" ip addresses where "worst" is measured by the number of Crit/Sig blacklists the IP is on. These top 100 IPs are also dynamically generated at page load by a single SQL statement that I made. Also the DB is raided at every page load to get the number of days each IP has been on each blacklist. The way I did this was using Oracle's TO_CHAR(), with format 'J'. Which is Julian date (number of days since January 1, 4713 BC (BCE)). The results are then natcasesort()ed by bond group company name and sub-sorted by IP. And of course you can select all IPs for a bond group (not just the top 100) with the dropdown, or click on an individual IP to see its full on list/off list history as far back as there's data in the DB.

The code to generate the page is only 445 lines of PHP.

The other thing I did for this was, I wanted to cache the names of all the bond groups, their bond group ids, and all the IP addresses. It's a four table join in the DB and it's pretty slow. So I installed memcached and wrote a bondgroupcache.php class that will raid the DB once, create a big array of arrays with all the info about all the bond groups and their enabled and disabled IPs, and then store a copy in Memcache. Then when someone else comes along and wants the same info, they instantiate another copy of the bondgroupcache class, and it pulls the info out of Memcache, thus avoing a slow and expensive DB hit. The class is also cool because it detects on the fly if you haven't loaded the Memcache PECL extension to PHP, or if memcache isn't running, and transparently falls back to fetching data from the DB. So it makes the class pretty bulletproof.
3 Comments | Post A Comment | | Link



browse
May 2015