Category Archives: PHP

PHP 5.3.1 now available in WHM/cPanel’s EasyApache

After much patience and persistence on the part of myself and many other individuals, we now have PHP 5.3.x support in EasyApache, starting with PHP 5.3.1.  For those of you who may be unaware, EasyApache is WHM/cPanel’s tool for creating custom compilations of Apache and PHP.  This solves many problems for those who have been doing this “behind the scenes,” as well as those who wish to utilize some of the great new features implemented in the 5.3 series.  PHP 5.3.1 introduces namespaces, late static binding, decreased memory usage (YMMV), several new extensions, and improved MySQL support.  Be sure to check your scripts for compatibility before going live with PHP 5.3.1 on a production server.  Some scripts will be affected by some of the changes, so testing is extremely important.

Using memcached with WordPress


Today, I decided to implement a popular distributed caching system called memcached.  Memcached allows PHP objects and variables to be stored in memory, which when used properly, can decrease page load time and server load.  Memcached can also work as a central cache for a cluster of servers.  File-based caching systems work by generating static files, and storing them in a local directory to be served in place of the dynamic content.  This can reduce the number of database queries, and help avoid having to process the script with each new request; however, there is a downside. Continue reading Using memcached with WordPress

PHP 5.2.12 released

PHP LogoWe’ve been paying close attention to new PHP releases, with a focus on the 5.3.x series release branch, but an important security update has been made to the 5.2.x branch.  The new max_file_uploads PHP directive will prevent DOS (denial of service) attacks that happen by using file uploads to create temporary file exhaustion.  This is an important one, and should be implemented as soon as possible.  Links to the release announcement, changelog, and download page are listed below.  On a side note, WHM/cPanel has not updated EasyApache yet, but we are assuming this will come soon.  We’ve also gotten word that, due to popular demand (thank you everyone), cPanel is working as fast as possible in getting PHP 5.3.1 into EasyApache (see cPanel forum post for more info:

Download PHP 5.2.12

Generate HTML drop downs from arrays & ranges with a PHP class

There comes a time (or a multitude of times) where a developer finds him- or herself rewriting the same code over and over again. Eventually, we get tired of it and need to find a solution. Recently, I frequently found myself writing code to generate HTML drop downs.  This became tedious, and I started to think it was unnecessary. But wait!  There must be a better way!  I didn’t want to use Zend_Form or any other 3rd party solution; I wanted to create my own class to help take care of this problem.  Below is the code/examples for the class, then a description of some of the methods, and lastly a link to download the source code.  As you can see, there are some nice features, and the class is easy to use and extend. Continue reading Generate HTML drop downs from arrays & ranges with a PHP class

PHP 5.3.1 is finally here!

PHP LogoAfter four release candidates, we finally have a stable PHP 5.3.1 release.  For those already running PHP 5.3.0, there’s not much that is different, but there are some improvements.  For others, it means there will probably be PHP 5.3 support in cPanel/WHM via EasyApache very soon.

In PHP 5.3.1, the max_file_uploads directive was introduced into php.ini to help prevent DOS (denial of service) attacks via file exhaustion.  max_file_uploads is set at 20 by default.  There were also several other security issues patches, and many bugs fixed in this release.  Links containing additional details are below:

PHP 5.2.12 RC1 and PHP 5.3.1 RC4 released!

Yes, that’s right, another PHP 5.2 version, and the fourth release candidate for PHP 5.3.1… the details are as follows:

  • PHP 5.3.1 RC4
    • Three bug fixes including one for mysqli and safe_mode_include_dir
    • Complete list
  • PHP 5.2.12 RC1
    • Added max_file_uploads as seen in PHP 5.3.1 RC3, which helps prevent DOS attacks occurring via temporary file exhaustion
    • Fixed Snow Leopard build error
    • Fixed make install-pear failure
    • Fixed parse_url() incorrect with ? in fragment
    • Complete list

Clearly, the PHP 5.2.12 release candidate is much more exciting than PHP 5.3.1’s, which tells me we are getting closer to a stable PHP 5.3.1 release.  A download link for both versions is included below.

Download PHP 5.3.1 RC4 or PHP 5.2.12 RC1

PHP 5.3.1 RC3 released!

We are yet another release candidate closer to PHP 5.3.1.  A link to download PHP 5.3.1 RC3 is included below, as well as links to the changelog and current bugs.  One bug fix will help prevent DOS (denial of service) attacks via a new INI directive labeled max_file_uploads.  This will default to 100 files per request.

Download PHP 5.3.1 RC3

10+ WordPress Functions Every Developer Should Know About

add_action($tag, $function_to_add, $priority, $accepted_args)
do_action($tag, $arg)

add_action() attaches a function to a specific action, which is then triggered by a do_action() call somewhere during execution. This can be used to execute a group of functions using the $priority parameter to determine order (optional), and arguments can be passed through the $accepted_args parameter. Below are a few examples of how this is used in the WordPress platform:

WordPress Logo

  • do_action(‘deleted_post’)
    This is executed after a post or page is deleted, and post or page ID is passed as a parameter.  This allows you add custom functionality whenever a post is deleted.  For example, lets say you want to be notified every time a post is deleted.  You can create a function to send the e-mail, and execute add_action(‘deleted_post’, ‘notify_when_deleted’, 10, $email). After that, when do_action(‘deleted_post’) is called, the notify_when_deleted() function will be called.
  • do_action(‘wp_head’)
    The wp_head action is traditionally called within a theme’s header.  If you wanted to create an SEO plugin, you could very easily add an action to wp_head to display meta tags. Continue reading 10+ WordPress Functions Every Developer Should Know About

jQuery Tablesorter helper function for WordPress

In one of my projects, I converted WordPress into a reporting engine, which is used at 20 car dealerships to track Internet sales.  During development, I found that I was writing the same code over and over again for the jQuery Tablesorter plugin, which allows you to sort tables using a simple JavaScript call.

First, I would have to queue the script file, then add the appropriate JavaScript. To ensure the JavaScript was executed at the right time, I had to create a function to use it with add_action().  I found this to be tedious and unnecessary, and wrote a simple helper function to remedy this.  The following function was added to /wp-admin/includes/template.php, but if you use it, it will most likely go in a plugin or theme include.  This will prevent it from being overwritten during WordPress upgrades. Continue reading jQuery Tablesorter helper function for WordPress

Zend PHP 5 Certification: Actual vs. Mock Test

Over the course of the past few months, I have been studying and preparing for the Zend PHP 5 Certification exam (ZCE).  During this time, I purchased two five packs of mock tests.  The mock tests mimic the format of the actual test very well, though there are minor differences.  The one thing you will notice right off the bat is that the mock test returns a grade of PASS, FAIL, or EXCELLENT.  The Zend web site says the following with regard to actual vs. mock testing:

Mimics the exact setup of the actual exam and includes 70 questions to be completed in 90 minutes. The questions are different from the ones used in the real exam, however, they are also more difficult and complex—thus, if you score well on this exam, you should be comfortable that you are well-prepared to take the real test.

I got so-so grades on the first few mock tests, but still managed to get a passing grade.  By the end, I had two tests in a row with a grade of EXCELLENT.  I found out in the beginning that the two areas needing the most work were PHP4/5 Differences and Streams & Network Programming.  I studied these areas and brought the scores up to pass, and even excellent eventually.  I continued to study, but was fairly confident that I could pass the exam based on the statement from Zend, and the fact that I had taken and passed eight mock exams, including two classified as “excellent.”

Unfortunately, it was not that simple.  I took the test yesterday, and did not pass.  I was really disappointed because of the amount of work I put into preparing, but even more so due to the statement on Zend’s web site.  The actual test was much harder than they led me to believe.  I think that the statement should be reworded to effectively show the difficulty of this test.

I write this as a warning to those who take the approach I took.  While the mock tests serve as a good benchmark, getting an excellent or passing grade (even eight times) should not be an indication that you will be able to pass.  I know what I have to do now, but I wish I knew this $125 dollars ago.