Super Useful PHP Helper Function

If you use PHP, especially when dealing with an API, you might want to see everything inside a variable. Normally you’d use print_r(); but that would normally return a big long line of unreadable text. Since PHP included formatting as whitespace if you wrapped the output in a <pre> tag you get a nicely indented view that is much more readable.

Here’s how you can do it super easy style, just add this function to your project:

function pretty_print($arg) {
  echo '<pre>';
  print_r($arg);
  echo '</pre>';
}

Then you can do something like:

$var = $_SERVER;
pretty_print($var);

Upgrading My Dev Box To PHP 5.4

First I tried recompiling, which I had done in the past to install mcrypt but this time it didn’t turn out pretty. I had all types of issues and after going down the google brick road for a few hours I resorted to MacPorts. That turned out better, but certain things we’re acting up (PDO socket connection to remote hosts via Laravel, if your curious).

So I partitioned a section of my harddrive, called it MAMP, and reinstalled snow leopard. Then I added xcode and MAMP PRO and now I’m golden! Not only can I choose between PHP 5.3 and 5.4 it also comes with a shiny control panel! I feel like the kid who’s never been to a restaurant and goes out to a steakhouse.

Installing xcode and mamp pro on snow leopard partition

My new Virtual Private Server

Over the past few months I had the opportunity to configure a VPS for a client whose sites on shared hosting had become slow and prone to permissions issues.  I am hardly a command line guy, I use a mac and love fancy GUI’s.  At first it was hard, how did all these people know all these commands! But over time I become more intrigued and started to fall in love with my terminal.

So I finally ditched my shared host that this website was hosted on and set up a VPS. VPS.net has got a one month free trial, I chose Ubuntu 10.04.4 LTS as my stack, preinstalled with apache, PHP, and mySQL.  I had a lot of fun configuring them as per this wonderful guide. Now I had my own box configured and ready to go to work. I have officially fallen in love. When I feel the need my VPS is always there ready for some hot ssh action.

OF course one of the first things I set up was WordPress, now I did this through SSH entirely from the command line, like a boss. That is a first after using WordPress for over 4 years! The one caveat I found was that I needed to enable modrewrite for permalinks to work.

I have installed APC so I can take advantage of WordPress’s built in object caching with some good results.  Anyone have tips on speeding things up?

Anyways that’s enough rambling, it’s almost two in the morning and I have work to do.

UPDATE:

I since have installed nginx, as apache was using up a lot of memory, the W3 Total Cache plugin has built in nginx support, so that was great. Additionally I installed Varnish and set it up to serve static content without cookies and finally I have set up cloudflare to serve as a CDN for my static files. Needless to say but my box is smoking fast (150ms at 250 hits/second) with minimal resources.

Tip: Only show the first full post on WordPress.

As you can see on my homepage, only the first post is shown, the rest are just titles. The reason behind this, search engines do not like duplicate content. If every post is shown on the homepage, the actual post page, and the archives then the search engines see 3 of the same articles with different URL’s. Another reason is that it makes scanning for an article much easier. I was inspired for this after seeing Ben Bleikamp’s Blog and loving the simplicity and ease of use.

Here is the highly simplified code I used to achieve this effect, of course yours will be quite different. The important part is the php if statements and the $count variable. Of course if you want you can hire me to implement this on your blog.











			



Redirect iPhone’s with Javascript

Here is a really quick code:

  <script type="text/javascript">
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    location.href='YOUR_DIRECTORY/';
  }
  </script>

Add this to your html document’s head section. Replace YOUR_DIRECTORY with the folder that contains your iPhone optimized site.

Web3Jobs – Internet job search 4 geeks

Aside

Are you looking for work to put your latest ajax skill to good use?  A few weeks ago I saw Jeffrey Way , an author at NetTuts.com, was giving away free coupon’s to join a new web design & development job board and happened to win one of them!   That is good because I need all the work I can get.

Now I have one available web3jobs FREE COUPON to give away to you, see bottom of post for details!

web3jobs.com job boardsWeb3Jobs.com is an online job board especially for web designers & developers as well as SEO, and IT Guy types.  I think this may be the most advanced and easy to use job board and even though they are currently in beta there seems to be a good amount of listings, at least for freelancer’s looking for work!

Web3Jobs looks to me to be the best online board in terms of signing up, ease of use, and cool ajax functionality!  We will see if it turns out to be as good as the other web design & development listing boards when the site launches in a few weeks.

With the grim outlook most economists agree on, I think it is vital to market yourself and your skillset.  Most of Complimedia Online‘s work has come from word of mouth and a previous job with a web hosting company.

I have one available FREE COUPON to give away to you, my readers!

This FREE COUPON allows you to create an account on Web3Jobs.

You pay nothing for a professional account!
Sign up before they open to the public!

To win sign up with this blog and leave a comment on this post as a registered user and I will pick the first one!