Tilde expansion in PHP

If you have ever written a PHP command line script and tried to pass a file to it using the POSIX tilde (~) shortcut to reference your home directory, you may have been surprised to learn that the operating system does not automatically expand tildes in paths.

Read More

Write tests, you might learn something

Writing unit tests for your code is widely regarded as a best practice. There are many excuses for not writing tests: time, cost, and the fun factor. Excuses aside, there are some Good Reasons to write tests for your code. I just discovered one today.

Read More

What Employers are Looking For

Employers looking for high-quality software developers are plentiful. At the January meeting of the Atlanta PHP user group Ari Waller shared some useful notes on what employers are looking for in 2013 (universally, not just in Atlanta).

Read More

Scaling Your Website: Three Stages

So, you have A Big Idea that will Revolutionize The World. Naturally, people will flock to your site and engage with it. Naturally, you are concerned about whether your infrastructure can handle success. You wish to plan for success, it would be foolish not to, eh? Don’t let enthusiasm (or ignorance) lead you to premature over-optimization. After all, your Big Idea has not yet passed the test of time.

Read More

Roll your own MAMP development environment

Pre-packaged MAMP, LAMP, and WAMP stacks have been common on developer’s computers for years. Such packages are convenient because they provide a single-step install process, with all components in the server stack preconfigured to work together, and off you go.

Read More

Box drawing in PHP

Back in the “good old days” of MS-DOS, you could draw lines, boxes, filled areas (think progress bars), and more using the extended ASCII character set (AKA code page 437).

Read More

How to install an SSL certificate for Apache, from start to finish

  1. Create an SSL key to use to generate the certificate signing request

(Save this, you’ll need it to install the certificate). To generate the keys for the Certificate Signing Request (CSR) run the following command from a terminal prompt:

<pre>openssl genrsa -des3 -out server.key 1024 Generating RSA private key, 1024 bit long modulus .....................++++++ .................++++++ unable to write 'random state' e is 65537 (0x10001) Enter pass phrase for server.key:</pre>

Enter a passphrase.

Now we&#8217;ll remove the passphrase from the key, so that you don&#8217;t have to enter this passphrase whenever you restart Apache:

<pre>openssl rsa -in server.key -out server.key.insecure mv server.key server.key.secure mv server.key.insecure server.key</pre>
Read More

Unshorten URLs with PHP and cURL

While working on a site that provides previews of URLs embedded in tweets using the awesome PhantomJS scriptable WebKit browser, and encountered difficulties when an URL shortener such as Bit.ly was used (as is almost always done when tweeting out a link to an interesting article or photo).

Read More

IE innerHTML CSS bug

Today I encountered a bug that affects every version of Internet Explorer from IE6 all the way through IE9. Here’s what happens.

Read More

Writing MySQL schema migrations: best practices

Building MySQL web applications with a team of developers will inevitably present the challenge of database schema changes. Any good web developer understands the importance of keeping all code under version control, but how many follow the same principle for the database?

Read More

http_build_query(): surprise!

Did you know that PHP’s http_build_query() drops any key from your query array if the value is NULL? I wonder how many subtle API client bugs are caused by this behavior.

Read More

Master-Master MySQL Replication…that hurts less

If you have ever touched a MySQL slave, you know that they can and do frequently halt. While sync problems can be caused by many things—network outages, schema changes, etc—one of the most common problems in a dual-master setup is primary key collision.

Read More

Uploading large files: covering all the bases

When uploading a file to a PHP script on an Apache web server, there are several configuration options that if improperly set can get in the way. I just encountered yet another one of these, and decided to catalog them here.

Read More

Takeaways from PHPCon, day 1

I’m here at PHPCon, the first PHP community developer conference in Nashville, TN. The first day consisted of two rather lengthy workshops, both of which were very informative.

Read More

Avoid the void(0) in IE6

I recently learned the hard way that <a href="javascript:void(0)"> doesn’t work as expected in IE6. The solution is to use the familiar # but make sure your onclick event returns false:

Read More

Improving INSERT INTO … SELECT Performance

INSERT INTO…SELECT locks the table being read by the SELECT statement due to MySQL 5.0’s statement-based replication. Here’s a great post from the MySQL Performance Blog explaining the problem in detail and what to do about it.

Read More

Notes on a great web demo

I recently sat in on a live demonstration of a piece of software my former employer was evaluating. Here are some notes on what makes a great webinar or web demo.

Read More

Handling errors inside shutdown functions

Using register_shutdown_function() to do stuff on script shutdown requires special error handling. Normal error handling does not work within the function called, so if an error occurs inside your shutdown function you get this nondescript error:

Read More

Skype hijacks port 80

Imagine my dismay and perplexity today when Apache suddenly stopped working on my development PC. Checking the Windows event log revealed this error:

Read More

jQuery hoverIntent plugin

hoverIntent is a plug-in that works like (and was derived from) jQuery’s built-in hover. However, instead of immediately calling the onMouseOver function, it waits until the user’s mouse slows down enough before making the call. Why? To delay or prevent the accidental firing of animations or ajax calls. Simple timeouts work for small areas, but if your target area is large it may execute regardless of intent.

Read More

Rules for Practical Programmers

Here are some observations I’ve gathered from writing a variety of programs in PHP over the last year. Do you have one I should add? Please share it and post it in the comments.

Read More

PHP Syntax Highlighting Refresh

When you spend your days staring at PHP code, you really can appreciate a visual refresh now and then. Syntax highlighting, if done well, makes reading code much easier. Excellent color schemes are not only functional, but are visually appealing as well.

Read More

AmCharts-PHP Library

Here’s a really cool library which makes it super-easy to generate the xml needed for AmCharts flash graphs in PHP.

Read More

Logical XOR in Javascript

XOR (exclusive OR) is a boolean operation, like && and ||, but with the following logic: It is true if the expression on either side is true (like ||), but not if both sides are true (like &&).

Read More

Alabama Scenery

Tuesday I stopped along the way as I was approaching Birmingham at a Chick-fil-a for lunch. Some creative florist had furnished all the tables with these flowers. They are not fake:

Read More

Adventures in Ubuntuland

My two-year-old HP laptop is getting slower and slower. Time for an XP re-install, but that’s a big ordeal. I opted to give Linux another try (maybe the third time will be the charm).

Read More

Managing large MySQL databases on a GB budget

I just wanted to quickly mention something about how MySQL handles out-of-disk-space situations when importing an SQL file. Here's my situation: I have an 80GB hard disk, 7GB free space, and am loading a 2GB SQL database dump . No problem, right? Well not always. I started it importing and went to bed. In the morning it hadn't finished and I was getting out-of-space notifications on my taskbar.
Read More