Archive for September, 2009

How to blog effi­ciently and get the most from your content

September 30th, 2009

How to get the most mileage from your content

Con­tent in large part, is the vehi­cle of choice in today’s Inter­net. As I see it, today’s inter­net is mostly about two things; infor­ma­tion or com­mu­ni­ca­tion (per­sonal and social). There will always be a cer­tain por­tion of the Inter­net reserved for busi­ness intranets and extranets but by in large we seem to feel that the best use of today’s Inter­net is a global soci­etal infor­ma­tion share. How can we cap­i­tal­ize and mon­e­tize that as con­tent writ­ers, arti­cle writ­ers and bloggers?

The best way that I have found to mon­e­tize con­tent is to write con­tent and pub­lish infor­ma­tion using the R.A.T con­tent prin­ci­ple. Using this prin­ci­ple will ensure that you get the most mileage from the con­tent that you work so hard to put together.

Rel­e­vant Content

The con­tent that you pub­lish to your audi­ence has to be rel­e­vant to your audi­ence. Don’t pub­lish con­tent about cars to an audi­ence that is in the health and fit­ness mar­ket.  It might not upset them ter­ri­bly but your not likely to get much viewer/readership. This pre­cludes that you have done the proper research to iden­tify what your audi­ence should be and where to find them.

Accu­rate Content

Accu­racy is fairly sim­ple, I’ll lis­ten to any­one once but if I find out they are giv­ing  me incor­rect infor­ma­tion I’m not likely  to lis­ten to them again. If your con­tent is not accu­rate it isn’t IF your audi­ence finds out your full of it, it is WHEN.  It is so sim­ple to have accu­rate con­tent that there is no excuse for pub­lish­ing inac­cu­rate con­tent. Sim­ply write about the things that you know, if you aren’t versed on a topic then don’t write con­tent about it. If you want to write about a topic that your not famil­iar with then com­mit to doing exhaus­tive research on the topic prior to writ­ing about it and make sure to tell your audi­ence that the con­tent is only based on your own per­sonal research. I would rather lis­ten to an hon­est per­son that is occa­sion­ally pub­lishes inac­cu­rate con­tent than a liar that I can’t trust con­tent from.

Time­less Content

I think ‘con­tent period’ this is the most impor­tant part of the R.A.T prin­ci­ple. Your con­tent needs to be as time­less as pos­si­ble so it can be reusable. By that I mean that your con­tent should be just as rel­e­vant and read­able two years from now as it is today. Avoid trending/fad top­ics (unless you don’t plan to reuse the con­tent) that won’t be rel­e­vant in a month or two. Refrain from ref­er­enc­ing or using cur­rent events to illus­trate your ideals.  In two years, some­one inter­ested in your topic may be read­ing your con­tent but won’t be able to relate to it because you illus­trate and idea by ref­er­ence to an event in your time that the cur­rent reader was unaware of and then the mes­sage just gets lost.

The Code­Tree rec­om­mends iCon­tact for mar­ket­ing list management

Writ­ten By:

Ryan Huff
ryan@rthconsultants.com

http://rthconsultants.com

Ryan Huff is a free­lance web devel­oper, tech­nol­ogy coach, mar­tial artist, busi­ness devel­oper and an avid inter­net mar­keter. You can con­nect with Ryan here at The Code­Tree or at RTH Con­sul­tants, fol­low @rthconsultants on Twit­ter or at Face­book

An alter­na­tive screen scrap­ing func­tion using PHP

September 30th, 2009
function load($url,$options=array()) {

    $default_options = array(
        'method'        => 'get',
        'return_info'    => false,
        'return_body'    => true,
        'cache'            => false,
        'referer'        => '',
        'headers'        => array(),
        'session'        => false,
        'session_close'    => false,
    );

    foreach($default_options as $opt=>$value) {

        if(!isset($options[$opt])) $options[$opt] = $value;
    }

    $url_parts = parse_url($url);

    $ch = false;

    $info = array(

        'http_code'    => 200

    );

    $response = '';

    $send_header = array(
        'Accept' => 'text/*',
        'User-Agent' => 'codeTree/1.00.A (http://www.mycodetree.com)'
    ) + $options['headers'];

    if($options['cache']) {

        $cache_folder = '/tmp/'; //CACHE FOLDER (MUST EXIST)

        if(isset($options['cache_folder'])) $cache_folder = $options['cache_folder'];

        if(!file_exists($cache_folder)) {

            $old_umask = umask(0); 

            mkdir($cache_folder, 0777);

            umask($old_umask);
        }

        $cache_file_name = md5($url) . '.cache';

        $cache_file = joinPath($cache_folder, $cache_file_name); 

        if(file_exists($cache_file)) { 

            $response = file_get_contents($cache_file);

            $separator_position = strpos($response,"\r\n\r\n");

            $header_text = substr($response,0,$separator_position);

            $body = substr($response,$separator_position+4);

            foreach(explode("\n",$header_text) as $line) {

                $parts = explode(": ",$line);

                if(count($parts) == 2) $headers[$parts[0]] = chop($parts[1]);

            }

            $headers['cached'] = true;

            if(!$options['return_info']) return $body;

            else return array('headers' => $headers, 'body' => $body, 'info' => array('cached'=>true));

        }

    }
    ///////////////////////////// Curl /////////////////////////////////////
    if(function_exists("curl_init") and (!(isset($options['use']) and $options['use'] == 'fsocketopen'))) {

        if(isset($options['post_data'])) {

            $page = $url;

            $options['method'] = 'post';

            if(is_array($options['post_data'])) {

                $post_data = array();

                foreach($options['post_data'] as $key=>$value) {

                    $post_data[] = "$key=" . urlencode($value);

                }

                $url_parts['query'] = implode('&', $post_data);

            } else {

                $url_parts['query'] = $options['post_data'];

            }

        } else {

            if(isset($options['method']) and $options['method'] == 'post') {

                $page = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'];

            } else {

                $page = $url;

            }

        }

        if($options['session'] and isset($GLOBALS['_binget_curl_session'])) 

        $ch = $GLOBALS['_binget_curl_session'];

        else 

        $ch = curl_init($url_parts['host']);

        curl_setopt($ch, CURLOPT_URL, $page) or die("Invalid cURL Handle Resouce");

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

        curl_setopt($ch, CURLOPT_HEADER, true);

        curl_setopt($ch, CURLOPT_NOBODY, !($options['return_body'])); 

        if(isset($options['method']) and $options['method'] == 'post' and isset($url_parts['query'])) {

            curl_setopt($ch, CURLOPT_POST, true);

            curl_setopt($ch, CURLOPT_POSTFIELDS, $url_parts['query']);

        }

        curl_setopt($ch, CURLOPT_USERAGENT, $send_header['User-Agent']);

        $custom_headers = array("Accept: " . $send_header['Accept'] );

        if(isset($options['modified_since']))

            array_push($custom_headers,"If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',strtotime($options['modified_since'])));

        curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);

        if($options['referer']) curl_setopt($ch, CURLOPT_REFERER, $options['referer']);

        curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/binget-cookie.txt");

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

        curl_setopt($ch, CURLOPT_MAXREDIRS, 5);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        if(isset($url_parts['user']) and isset($url_parts['pass'])) {

            $custom_headers = array("Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass']));

            curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);

        }

        $response = curl_exec($ch);

        $info = curl_getinfo($ch);

        if($options['session'] and !$options['session_close']) $GLOBALS['_binget_curl_session'] = $ch;

        else curl_close($ch);

    //////////////////////////////////////////// FSockOpen //////////////////////////////
    } else {

        if(isset($url_parts['query'])) {

            if(isset($options['method']) and $options['method'] == 'post')

                $page = $url_parts['path'];

            else

                $page = $url_parts['path'] . '?' . $url_parts['query'];

        } else {

            $page = $url_parts['path'];

        }

        if(!isset($url_parts['port'])) $url_parts['port'] = 80;

        $fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, 30);

        if ($fp) {

            $out = '';

            if(isset($options['method']) and $options['method'] == 'post' and isset($url_parts['query'])) {

                $out .= "POST $page HTTP/1.1\r\n";

            } else {

                $out .= "GET $page HTTP/1.0\r\n";
            }

            $out .= "Host: $url_parts[host]\r\n";

            $out .= "Accept: $send_header[Accept]\r\n";

            $out .= "User-Agent: {$send_header['User-Agent']}\r\n";

            if(isset($options['modified_since']))

                $out .= "If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',strtotime($options['modified_since'])) ."\r\n";

            $out .= "Connection: Close\r\n";

            if(isset($url_parts['user']) and isset($url_parts['pass'])) {

                $out .= "Authorization: Basic ".base64_encode($url_parts['user'].':'.$url_parts['pass']) . "\r\n";

            }

            if(isset($options['method']) and $options['method'] == 'post' and $url_parts['query']) {

                $out .= "Content-Type: application/x-www-form-urlencoded\r\n";

                $out .= 'Content-Length: ' . strlen($url_parts['query']) . "\r\n";

                $out .= "\r\n" . $url_parts['query'];

            }

            $out .= "\r\n";

            fwrite($fp, $out);

            while (!feof($fp)) {

                $response .= fgets($fp, 128);

            }

            fclose($fp);

        }

    }

    $headers = array();

    if($info['http_code'] == 404) {

        $body = "";

        $headers['Status'] = 404;

    } else {

        $header_text = substr($response, 0, $info['header_size']);

        $body = substr($response, $info['header_size']);

        foreach(explode("\n",$header_text) as $line) {

            $parts = explode(": ",$line);

            if(count($parts) == 2) $headers[$parts[0]] = chop($parts[1]);

        }

    }

    if(isset($cache_file)) {

        file_put_contents($cache_file, $response);

    }

    if($options['return_info']) return array('headers' => $headers, 'body' => $body, 'info' => $info, 'curl_handle'=>$ch);

    return $body;

} 

//USAGE
$contents = load('http://example.com/rss.xml');

The basics of Neuro-linguistic Programming

September 29th, 2009

The basics of neuro-linguistic pro­gram­ming and how to incor­po­rate it into a mar­ket­ing strategy

Neuro-linguistic pro­gram­ming (NLP) can be defined as a sys­tem of com­mu­ni­ca­tion regard­ing rela­tional behav­ior pat­terns and the sub­jec­tive expe­ri­ences asso­ci­ated with them. There are meth­ods used by ther­a­pists based on NLP  which seeks to enlighten peo­ple in com­mu­ni­ca­tion and self-presence while attempt­ing to change pat­terns of men­tal and emo­tional behavior.

NLP is widely regarded as a sub­jec­tive sys­tem and lacks solid, sub­stan­tial evi­dence to speak to it’s reli­a­bil­ity and cred­i­bil­ity. How­ever, there is enough sug­ges­tive the­ory to enter­tain the sys­tem with some mea­sure of prac­ti­cal­ity. You’ll have to judge whether NLP tech­niques are valid and right for your mar­ket­ing strategy.

Basic NLP Techniques

Dif­fer­ent sources on NLP will describe these tech­niques in much larger detail but I’ll inten­tion­ally keep it short and simple.

Rap­port / Reflection

In it’s most sim­plest form is mim­ic­k­ing or copy­ing the phys­i­cal and vocal inflec­tions of some­one or some group (or the per­cep­tion of some­one or some group) in order to put your­self on the same level as that per­son or group so as to be accepted by and iden­ti­fied with. Some may describe this as, ‘blend­ing in’. When the Pres­i­dent of the United States goes to speak to work­ers on a dock he takes off his suit coat, rolls his cuff’s a bit, loses his neck tie, unbut­tons the col­lar but­ton on his shirt and makes more casual ges­tures and walk­ing strides. This is because he wants the work­ers to iden­tify with him; when a lis­tener iden­ti­fies with a speaker he or she is much more inclined to receive, recall and sup­port the mes­sage that the speaker is delivering.

Anchor­ing

Think of anchor­ing like con­di­tion­ing or train­ing. You have to teach your audi­ence what to respond to by asso­ci­at­ing action with rec­og­nized and dis­tin­guished cues. A very pop­u­lar blog­ger can get his read­ers to share/syndicate his or her blog posts (the action) by sim­ply post­ing the blog (the cue) because the blog­ger is very pop­u­lar (the anchoring/conditioning/training). The blog­ger estab­lishes him/herself as an expert author­ity and con­di­tions the audi­ence to rec­og­nize that the blog posts are author­i­ta­tive. When the blog­ger makes a new post, it trig­gers the audi­ence to read/share it because the audi­ence per­ceives it to be authoritative.

Swish

This tech­nique allows for fast, re-directed think­ing and in NLP is used to divert focus from unwanted thoughts/behavior to more desired thoughts/behavior by attempt­ing to dis­rupt the pat­tern of behav­ior that leads to the unwanted thoughts or behav­ior. The Swish starts by visu­al­iz­ing the trig­ger that starts the pat­tern of unwanted behav­ior and then switched sev­eral times with visu­al­iza­tions of more desired thoughts or behavior.

Refram­ing

Not unlike Anchor­ing, refram­ing deals with stim­uli and asso­ci­ated action. In con­trast to anchor­ing how­ever, refram­ing attempts to alter the action asso­ci­ated to the stim­uli by chang­ing the per­cep­tion of the stim­uli. By chang­ing the way some­one thinks about or sees some­thing you can poten­tially alter the way they react to it. I know that cig­a­rettes are bad for me but when I see happy peo­ple hav­ing a good time with friends while hav­ing a cig­a­rette in their hand, I may per­ceive that cig­a­rettes aren’t as bad as I once thought because happy and good thoughts have been asso­ci­ated with cig­a­rettes. Cig­a­rettes may not be the great­est exam­ple because so much neg­a­tiv­ity sur­rounds them that I don’t think any amount of refram­ing could offset.

Proven or not, these tech­niques are already in play in many dif­fer­ent busi­nesses for many dif­fer­ent uses, regard­less if you label them NLP or not.

I feel that a suc­cess­ful mar­ket­ing strat­egy can greatly ben­e­fit from the strate­gist being well versed in con­tem­po­rary under­stand­ings of the human mind.  If one can bet­ter under­stand how we think then he/she can bet­ter serve us on a deeper more sat­is­fy­ing level.

The Code­Tree rec­om­mends iCon­tact for mar­ket­ing list management

Cre­ate dae­mon child processes with PHP

September 29th, 2009
/**
 * System_Daemon turns PHP-CLI scripts into daemons.
 *
 * PHP version 5
 *
 * @category  System
 * @package   System_Daemon
 * @author    Kevin 
 * @copyright 2008 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php
 * @version   SVN: Release: $Id: logparser.php 215 2009-04-25 10:10:18Z kevin $
 * @link      http://trac.plutonia.nl/projects/system_daemon
 */

/**
 * System_Daemon Example Code
 *
 * If you run this code successfully, a daemon will be spawned
 * but unless have already generated the init.d script, you have
 * no real way of killing it yet.
 *
 * In this case wait 3 runs, which is the maximum for this example.
 *
 *
 * In panic situations, you can always kill you daemon by typing
 *
 * killall -9 logparser.php
 * OR:
 * killall -9 php
 *
 */

// Allowed arguments & their defaults
$runmode = array(
    "no-daemon" => false,
    "help" => false,
    "write-initd" => false
);

// Scan command line attributes for allowed arguments
foreach ($argv as $k=>$arg) {
    if (substr($arg, 0, 2) == "--" && isset($runmode[substr($arg, 2)])) {
        $runmode[substr($arg, 2)] = true;
    }
}

// Help mode. Shows allowed argumentents and quit directly
if ($runmode["help"] == true) {
    echo "Usage: ".$argv[0]." [runmode]\n";
    echo "Available runmodes:\n";
    foreach ($runmode as $runmod=>$val) {
        echo " --".$runmod."\n";
    }
    die();
}

// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path').':..');

// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";

// Setup
$options = array(
    "appName" => "logparser",
    "appDir" => dirname(__FILE__),
    "appDescription" => "Parses vsftpd logfiles and stores them in MySQL",
    "authorName" => "Kevin van Zonneveld",
    "authorEmail" => "kevin@vanzonneveld.net",
    "sysMaxExecutionTime" => "0",
    "sysMaxInputTime" => "0",
    "sysMemoryLimit" => "1024M",
    "appRunAsGID" => 1000,
    "appRunAsUID" => 1000
);

System_Daemon::setOptions($options);

// Overrule the signal handler with any function
System_Daemon::setSigHandler(SIGCONT, array("System_Daemon",
    "defaultSigHandler"));

// This program can also be run in the forground with runmode --no-daemon
if (!$runmode["no-daemon"]) {
    // Spawn Daemon
    System_Daemon::start();
}

// With the runmode --write-initd, this program can automatically write a
// system startup file called: 'init.d'
// This will make sure your daemon will be started on reboot
if (!$runmode["write-initd"]) {
    System_Daemon::log(System_Daemon::LOG_INFO, "not writing ".
        "an init.d script this time");
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::log(System_Daemon::LOG_NOTICE, "unable to write ".
            "init.d script");
    } else {
        System_Daemon::log(System_Daemon::LOG_INFO, "sucessfully written ".
            "startup script: ".$initd_location);
    }
}

// Run your code
// Here comes your own actual code

// This variable gives your own code the ability to breakdown the daemon:
$runningOkay = true;

// This variable keeps track of how many 'runs' or 'loops' your daemon has
// done so far. For example purposes, we're quitting on 3.
$cnt = 1;

// While checks on 3 things in this case:
// - That the Daemon Class hasn't reported it's dying
// - That your own code has been running Okay
// - That we're not executing more than 3 runs
while (!System_Daemon::isDying() && $runningOkay && $cnt <=3) {
    // What mode are we in?
    $mode = "'".(System_Daemon::isInBackground() ? "" : "non-" ).
        "daemon' mode";

    // Log something using the Daemon class's logging facility
    // Depending on runmode it will either end up:
    //  - In the /var/log/logparser.log
    //  - On screen (in case we're not a daemon yet)
    System_Daemon::log(System_Daemon::LOG_INFO,
        System_Daemon::getOption("appName").
        " running in ".$mode." ".$cnt."/3");

    // In the actuall logparser program, You could replace 'true'
    // With e.g. a  parseLog('vsftpd') function, and have it return
    // either true on success, or false on failure.
    $runningOkay = true;
    //$runningOkay = parseLog('vsftpd');

    // Should your parseLog('vsftpd') return false, then
    // the daemon is automatically shut down.
    // An extra log entry would be nice, we're using level 3,
    // which is critical.
    // Level 4 would be fatal and shuts down the daemon immediately,
    // which in this case is handled by the while condition.
    if (!$runningOkay) {
        System_Daemon::log(System_Daemon::LOG_ERR, "parseLog() ".
            "produced an error, ".
            "so this will be my last run");
    }

    // Relax the system by sleeping for a little bit
    // iterate also clears statcache
    System_Daemon::iterate(2);

    $cnt++;
}

// Shut down the daemon nicely
// This is ignored if the class is actually running in the foreground
System_Daemon::stop();