Joined the Mailout Interactive team!

Over the Christmas holidays I was asked if I would be interested in being interviewed for a web developer position at a local company called Mailout Interactive. Most noted for their email communication tools.

It was one of those opportunities that I was not expecting, I had seen the job posting and figured I was under qualified. Lucky for me my personal contacts at MI thought differently about me.

I am just about through week three here and have had a great time. It’s nice to be appreciated and have a good team of people behind me.

I am really glad to have made the move professionally and personally.

Regular Expression for URLs using ereg_replace

Ever needed a Regular Expression to parse URLs in a body of text. The beauty with this expression is its flexibility, it will handle a http or https url with or without www and it’s fine with tinyurls.

// $message contains a body of text with non html URLs
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $message);

$subject will be the body of text containing flat text urls. $text will now contain our information.

// Output New formatted content with links.
echo $text;

Now our content is parsed with URLs.

Done!

Appcelerator Acquires Aptana

Well Aptana 3 has been in beta for a long time with little happening in the past 6 months or more. Today Appcelerator has acquired Aptana and expects to have something out by Q1 of this year.

What does this mean?

Appcelerator®, the leading platform for rapidly developing native mobile, desktop, and tablet applications using Web technologies announced today that it has acquired Aptana®, the leading integrated development environment (IDE) for building web applications. The acquisition sets the stage for a new standard in next-generation application development by providing Web developers with a best-in-class, enterprise-grade development platform to rapidly build rich native applications that integrate easily with the cloud. The acquisition also brings together two of the world’s largest web development communities, Appcelerator’s and Aptana’s, to create a huge application development base of over 1,500,000 application developers.

appcelerator.com

PHP’s Memory Usage

This is a handy little Snippet that goes well with PHP Microtime. Not only are we concerned with our scripts execution time but we also want to make sure we are not using an exorbitant amount of memory in the process.

At the top of your script lets place the code that will start PHP’s Micro time.

$time_start = microtime(true);

At the bottom of your page, just before the “” tag we will put the Code that will calculate the execution time as well as how much memory was used to execute the script.

// RENDER TIME
$time_end = microtime(true);
$time = $time_end - $time_start;

echo &quot;Loaded in \n&quot;;
echo round($time, 3).&quot; Seconds &lt;br /&gt;&quot;;
echo 'Peak: ' . number_format(memory_get_peak_usage(), 0, '.', ',') . &quot; bytes\n &lt;br /&gt;&quot;;
echo 'End: ' . number_format(memory_get_usage(), 0, '.', ',') . &quot; bytes\n&quot;;

number_format() simply formats the number out put to look something like this “111,964″ instead of “111964″.

memory_get_peak_usage() is going to return a value based on the peak memory used during the execution. This is more so were we want to see improvements made.

memory_get_usage() will return the amount of memory used once the script is done processing, basically the amount currently used once the crunching is finished.

It’s a good idea to think about memory usage when you are making web applications as this can impact your hosting.

Say you have a VPS server with 256mb of ram but the foot print of each user is 25mb you can can only have about 10 people accessing your site before you running server errors exceeding memory limits. Any work involving processing of images a lot of data manipulation can eat up memory in a hurry.

Running PHP5 in the Dreamhost CLI

Some times a PHP framework might include a command line interface, Cake PHP or Symfony for example have a tool that will generate some code based on your database.

Symfony unlike Cake PHP will only work with PHP 5, When I tested the version of php on the front end I got 5.2.4 and figured I’m good to go.

While after running the Symfony command line tool to build my project I got a php error.

This is due to the setup of most shared web hosting environments PHP is run as CGI, or FastCGI rather than mod_php.

My knowledge of the command line is just enough to make trouble for myself and the support team.

As the Symfony documentation stated I checked the CLI php version and found it to be 4.4.9 using php -v and that the configuration would not work with Symfony.

I had a look in the DreamHost Wiki and found this could be fixed by adding an alias to your path.

DreamHost by default has PHP installed with the option to run php 5.

  • PHP 4 – /usr/local/bin/php
  • PHP 5 – /usr/local/php5/bin/php
  • PHP 5.3 – /usr/local/php53/bin/php

Open your .alias file using FTP or command line.

Add the following alias to the bottom of the file.

alias 'php=/usr/local/php5/bin/php'

This should work for any web-server but the path will be different.

Work with RSS feeds using PHP and cURL

cURL or Client URL Library is a very powerful tool, and its something that i recently had to use while working with two APIs one for Unfuddle and one for HelpSpot.

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

These functions have been added in PHP 4.0.2.

You can interact with most APIs using cURL, at first it seams intimidating but once you start to use it you become comfortable with the set up.

Lets get started by parsing an RSS feed.

Continue reading “Work with RSS feeds using PHP and cURL” »