Category Archives: PHP

PHP: Fastest way to check if an array is empty

I just posted benchmarks for checking for an empty string that I ran when looking to improve the efficiency of an application. Another simple benchmark I ran was for ways to check if an array is empty.

Like strings, there are a ton of ways to check if am array is empty. These here are not exhaustive, but a few that I chose to test:

  1. !$array
  2. $array == false
  3. empty($array)
  4. count($array) == 0
  5. $array == array()

PHP: Fastest way to check if a string is blank

I run an application that requires a very high level of efficiency due to very high volume. I recently did an evaluation of efficiency for this application and performed a benchmark on a number of important aspects of the code. My findings were very interesting.

As you may know, there are a ton of ways to check if a string is empty. These here are not exhaustive, but a few that I chose to test:

  1. !$string
  2. $string == false
  3. empty($string)
  4. strlen($string) == 0
  5. $string == ” Continue reading

How to install PHP Memcache on Windows WAMP, Linux for any operating system (without really installing)

I have a site that runs on Linux in production that uses Memcache. Installing Memcache on Linux is a cinch. I was setting this site up in my development environment however (Windows 7 64-bit, with WAMP, specifically Apache 2 and PHP 5.3) and I quickly discovered it’s not so easy. For the life of me, I could not find the correct php_memcache.dll file.

After spending a ton of time unsuccessfully install Memcache on my local machine, I realized that I don’t even need the memory caching functionality of Memcache, I just need the functions to work. Continue reading

How to Install PHP APC on Fedora & CentOS

APC (or Alternate PHP Cache) is a popular PHP PECL extension that can be used for PHP op-code caching. It is very stable and can significantly reduce page rendering times. It works by caching the PHP binaries, so that PHP doesn’t have to compile them on every request.

Installation is simple:

1. Use yum to install necessary packages.

# yum install php-pear php-devel httpd-devel pcre-devel

Continue reading