Categories

Tags

Page 24 of All Articles

Check if PHP is running from the command-line

When running PHP from the command-line interface, the availability of some variables and functionality may or may not be available. Case in point, when running command-line PHP sessions are not available and $_SESSION is undefined. When you’re on the command-line there’s also the possibility that you want to use the […]

Check if a PHP class exists

We’ve discussed how to check if a class has a function but what if the class doesn’t exist at all? To check if a class exists you can use, use guessed it, class_exists(). if (class_exists('MyClass')) { $object = new MyClass(); } else { throw new Exception('The class MyClass does not […]

WP Engine Review

Now that I’m back on the WordPress bandwagon and have been using WPEngine for a bit of time now, it’s time to talk about it. As previously discussed, I opted to use a hosted WordPress solution because of my utter disdain for administering WordPress. When researching WordPress hosts, I got […]

Check if a PHP class has a certain function

We’ve previously discussed how to check if a function exists but that only works on standalone functions like the ones built into PHP as well as any user defined functions. Luckily there’s a function for that called method_exists(). When speaking in the scope of a class, the functions are referred […]

Check if a PHP function exists

Let’s use json_encode as an example here. Prior to PHP 5.2.0 JSON support was only available via a PECL extension and since 5.2.0 it’s been available as part of the PHP core. You could check that the server is running PHP 5.2.0 or above, but that could result in a […]

Detect Required PHP Version

If you write and/or use open source software, you know that running an up to date version of PHP is a must. This can be a problem sometimes, like if you are running on a host that doesn’t run the most up to date version of PHP. Another scenario would […]

Rediscovering WordPress

If you’ve followed this blog for long enough you know that I’ve been through quite a few platform solutions over the years. Started with a homegrown blog, moved to WordPress, back again, moved to Tumblr and finally settling on Jekyll & Github because of it’s simplicity as well as the […]

Convert Errors to Exceptions in PHP

I was having a conversation with a buddy of mine the other day and we got on the topic of PHP not having a very standardized error system. Now that he’s working with Python the mix of errors and exceptions in PHP is an apparent shortcoming. PHP is funny like […]

Why I always wear a helmet

When I first starting biking as my primary mode of transportation to my office I felt like I was wearing a helmet mainly because I hadn’t rode a bike in something like 15 years. It’s true what they say, you never forget how to ride a bike (barring a debilitating […]

Speed up PHP with APC

The Alternative PHP Cache (APC) is a PECL package that provides an opcode cache for PHP. Rasmus Lerdorf is the lead of the project along with a handful of other developers. What is an opcode cache? Before I can answer that, let’s discuss how PHP works. Because it is an […]

How to Build a Leaderboard with PHP and Redis

One of biggest draws to Redis for me is the fact that it has more data structure types than just key / value. These additional data structures allow you to do some amazing things while still benefitting from being in-memory. One of the most notable ways to leverage Redis would […]

Getting a User's IP Address in PHP

Getting the IP address of a user seems like a pretty trivial task but you can’t always rely on $_SERVER['REMOTE_ADDR']. The super global value is the most reliable source because it is extracted directly from the TCP stack but if you’re behind a load balancer that address would be that […]

Recruiters need to learn to listen

If you’ve ever seen my LinkedIn profile you know that I don’t take my professional life all too seriously and that I also have an underlying disdain for recruiters. Have I been through a recruiting company before to get a job? Absolutely, but I’d never do it again (most likely). […]

PHP Redis Clients

In a previous post I’ve talked about installing phpredis a PHP Extension for Redis that has to be compiled from source. But what if you’re hosting scenario doesn’t allow you to compile extensions? Well you’re in luck, in addition to the extension, there are additional client libraries out there for […]

How to Install Wordpress on Ubuntu 12.04 LTS

Let’s be honest, sometimes we don’t necessarily want to start a site from scratch, especially a blog. There’s so many blogging platforms out there, why reinvent the wheel? Arguably the most well known, Wordpress, is very easy to install on Ubuntu 12.04 LTS. First things first, you will need to […]

How to Install the SQLite Module on Ubuntu 12.04 LTS

SQLite is a self-contained, serverless, zero-configuration, transactional SQL database engine. The SQLite website also boasts that it is the most widely deployed SQL database engine in the world. As I’ve previously discussed, SQLite has the advantage over MySQL as it can be used as an internal session handler with PHP. […]

Moving out of the cloud

It’s been nearly 4 years since I made the switch from a dedicated server to the cloud. It was August 15th, 2009 and I was tired of how much I was paying for a dedicated server, even considering that I was only covering half of the cost with my friend […]

How to Install the Memcached Module on Ubuntu 12.04 LTS

Installing the Memcached module for PHP on Ubuntu 12.04 LTS is as simple as can be. First let’s make sure we have Memcached installed: sudo apt-get install memcached On Ubuntu, the process to install the PHP module is similar to how we installed Memcached itself: sudo apt-get install php5-memcache php5-memcached […]

SQLite as a PHP Session Handler

Now that I’ve discussed the in-memory data stores (NoSQL if you will) let’s switch gears to a more traditional RDBMS. SQLite by definition is a software library that implement a self-contained server-less, zero-configuration, transactional SQL database engine. It’s more important claim to fame is that it is the most widely […]

Redis as a PHP Session Handler

Redis is one of my favorite key-value stores, the range of data types alone make it a must have in any developer”s tool belt. Another great use for Redis is as your session handler in PHP. The optional persistence that Redis provides makes it a better option than using Memcached […]

Memcached as a PHP Session Handler

Memcached makes a semi-perfect solution for storing your PHP sessions. Why only semi-perfect? Well in Memcached’s defense, the fact that it is an in-memory data store makes it a great choice because of the speed. The negative is the lack of persistence, which makes it somewhat less desirable. What this […]

Installing PHP Redis - A PHP Extension for Redis

Redis is one of my favorite new data stores of the NoSQL movement. It has the power and speed to act as a caching server like Memcached and it has more advanced data types to make it more like an RDBMS. Before we can talk about using Redis as a […]

Calculate Age from Date with PHP

Calculating the age based on a date is a pretty simple task that can be accomplished many different ways (Google yield’s quite a few different approaches). The caveat that usually arises is that you need to factor in which side of the birthday you are on based on the day’s […]

Apple iOS 7 Beta Review

Like many people, I went ahead and upgraded my phone to the Developer Preview of Apple’s latest iOS, version 7. Days later, I’m wondering if I will be downgrading next week because of a handful of issues that I would consider to be critical defects for my own usage. It’s […]

Configuring PHP Sessions

Now that we know how to use sessions and have built a simple login system, let’s take a look at some options for configuring PHP sessions. Out of the box, PHP is configured to file-based sessions with a max lifetime of 1440 seconds (a mere 24 minutes). Garbage collection probability […]