Fetching Dilbert Comic stripts from rss feed

10:17PM Apr 17, 2009 in category PHP by Alexander Pirsig

This is a php script to fetch dilbert images out of a feedburner feed. Its a quick an dirty implementation it works and I'm sure there are bug's in it.

Enjoy! :D ... ah you can find the testside here -> testside or download it here
<\?php
/**
 * Make Sure XML is cached for couple of minutes
 */
$tmpfile = '/tmp/dilbert.rss';
$gap = 60*60*1; # 1 hour(s)

if(file_exists($tmpfile)===true && (filemtime($tmpfile)+$gap)>time())
{
  # Use locale cached dilbert Content
  $xmlStr = file_get_contents($tmpfile);
}
else
{
  # Reload Cached DilbertFeed
  if(!file_exists($tmpfile))
  {
    touch($tmpfile);
  }
  $xmlStr = file_get_contents('http://feeds2.feedburner.com/DilbertDailyStrip?format=rss');
  file_put_contents($tmpfile,$xmlStr);
}
$xml = new simpleXMLElement($xmlStr);
$content = $xml->xpath('//item');
\?>








  • ".$content[0]->title.""; ?> <\?php preg_match($expr,$content[0]->description,$matches); \?> enclosure['url'] = $matches[1]; \?> <\?php echo "".$content[0]->title.""; \?> <\?php echo "
    Fetched: ".date('Y-m-d H:i:s', filemtime($tmpfile)); \?>

Kommentare[0] Tags: php simple xml dilbert xpath coding labs rss

Quick Guide to use FirePHP + FireBug Console

09:30PM Apr 16, 2009 in category PHP by Alexander Pirsig

This is a quick guide to use FirePHP + Firebug to write debug output to firebug console. FirePHP is a Log-Appender for firebug console. With this piece of code you write php debug output directly to firebug console.

The requirements

So let's get started for beginning you need four things: After you've installed firephp and firebug in firefox, you have a "small bug icon" in the lower right corner that looks like this.

Netconsole settings

Next we're go to the test site and activate firephp. So type in http://labs.pirsig.net/firephp/firetest.php click on the Firebug icon. Next click on the Net-Tab and activate the "console" and "net" checkbox.

Net-Console Output

Next Click on "Console" and reload the site you should see some debug output in firebug console.

Testside PHP-Code

Enclosed is the php code for the testside
// Include FirePHP OOP Class
require_once("FirePHP.class.php");

// Define a Global DEBUG flag
// This should probly go to a central place
DEFINE(DEBUG,true);

// Get a instance the true automaticly create's
// an instance and makes sure there is only one
// registered (singleton)
$fb = FirePHP::getInstance(true);

// Array's with firephp configuration
//
// maxObjectDepth      Maximum depth to traverse objects.
// maxArrayDepth       Maximum depth to traverse arrays.
// useNativeJsonEncode Set to FALSE to use JSON encoder included
//                     with FirePHPCore instead of json_encode().
// includeLineNumbers  Include File and Line information in message.
// Defaults:
$options = array('maxObjectDepth' => 10,
                 'maxArrayDepth' => 20,
                 'useNativeJsonEncode' => true,
                 'includeLineNumbers' => true);

$fb->setOptions($options);

// Define to control global debug input output
$fb->setEnabled(DEBUG);

// Displays different kind of log output
$fb->log('Hello log');
$fb->info('Hello info');
$fb->warn('Hello warning');
$fb->error('Hello error');

echo "Normal site output";

Related sites

Kommentare[0] Tags: labs firephp javascript console debug php firebug error-handling

Handle debug output ... not

01:33AM Apr 15, 2009 in category PHP by Alexander Pirsig

First of all remember you should NEVER EVERY PUT DEBUG OUTPUT ON LIVE SITES. In my time as php developer I came across a couple of NOT-Solutions. They are very funny but you should not use it (even in development) :)

The if($_SESSION['user']=="LAMMO") - method


intention: Your think it's not smart to use a logging facility.
implication:It's only a good solution if customers have the chance to review your code. To see how smart you are hidding everthing in a session. WOHOWW. It's also fun to have this extra performance sucking code snippets in your source code for presentation purpose to make sure they see the debug output!
implementation:

if($_SESSION['user'] == "LAMMO") echo $debug;
// * plz make sure not using any brackets! to get the best lammo result :)

I hide my content in the side something - tactic


intention: Your're smart ass and like to be cool so your place a font tag a round you debug output
implication: Google and Co. will index your site
implementation:

<\?php echo debug("asdf"); \?>

Use the Debug Pixel


Use the debug pixel

intention: don't get indexed by a search engine
implication: everyone can see you're debug output
implementation:




Okay okay the last one is just a prove of concept, we discused this while we've tried to find the best baddest solution to put debug output in a live environment

hope you had fun ;)

Kommentare[0] Tags: labs php coding antipattern log output logger debug