Fatal Error: Allowed Memory Size Exhausted in PHP

Today, I ran into this fatal error when trying to post to a WordPress blog. In Firefox 2 this error message was dumped to the screen:

Fatal error: Allowed memory size of 8388608 bytes exhausted

This error message is saying that the software needed more than 8MB of memory to perform its function. You may need to look in an error log file to read the message as some famous browsers may just give you a blank screen!

Found solutions for fatal memory errors:

If you can’t find your php.ini file, try submitting a help ticket to your host and request them to change the value for “memory_limit” in php.ini to 16M or 24M. Doubling or tripling the default memory allocation should do the trick. This way, any PHP script will have a larger working memory.

Round Numbers to Next Whole Number in PHP

Time for a new php function, ceil().

A client needed to record the hours spent in particular activities by each member. The number of hours spent in assigned activities were to be entered in whole numbers, where partial hours were rounded up to the nearest hour. So, if someone spent an hour and twenty minutes on a particular activity they were to enter 2 hours into the web site form. However, as we all know, directions are not always read, so don’t trust your input.

Validate all database input!

What was the computer going to spit out on the reports when a person entered 1.3 instead of 2? Naturally the output was rounded down to 1 hour instead of up to 2 hours.

To round up all fractional numbers php has a function that allows us to round all fractions up to the next highest whole number: ceil(argument);

Use it like so:

ceil(5.34) produces the value 6, while ceil(5.56) also gives us 6.

You can throw a variable in the parentheses instead of decimals:

$time_spent = ceil($hours);

Using ceil() allowed me to format the data before it was inserted into the database. Now, reports of member activities will indicate the appropriate time spent.

Time to Update WordPress to Version 2.6

Well, it’s time to update my local copy of WordPress. Version 2.6 has been out for a while, a couple weeks at least, and I’m willing to update my Vista copy now.

I’m sure that I don’t have to wait for the kinks to be ironed out once a new version of WP is released, but somehow I feel better waiting a little while before investing the time to backup and update. Of course, that’s because I’ve been burned before. You can waste a lot of time updating software only to have to go through it all again because of bugs that come crawling out once the software was released into the wild.

WordPress developers have addressed 194 bugs in version 2.6! Beyond those incremental improvements to the blogging software, WordPress now will count your words, caption your images and let you drag-n-drop to reorder galleries.

More improvements include version tracking, which records each version of posts that you or other authors make on your blog. Very handy for finding and fixing mistakes and monitoring who posted what and when.

For those of you that use media-rich sites you’ll be wanting to try out the new “post from where ever” feature. All you have to do is hit Press This! and the WordPress bookmarklet takes care of the rest.

How To Set Cookies to Zero Days for a WordPress Blog

Uncomfortable with having your WordPress blog keep subscribers and editors signed in even after closing their browsers?

Here’s how to delete cookies from your WordPress blog. You’ll have to modify a file in the root directory of your WP installation.

Look for the file called wp-pass.php – it should contain php code like so:

require( dirname(__FILE__) . '/wp-config.php');


if ( get_magic_quotes_gpc() )
$_POST['post_password'] = stripslashes($_POST['post_password']);


// 10 days
setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH);


wp_safe_redirect(wp_get_referer());

See that line that starts with setcookie?

All you have to do is change “864000” to “0” and the cookie drops from 864,000 seconds to zero seconds. So, the setcookie line should look like this:

setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 0, COOKIEPATH);

When the user closes their browser, the session is complete and the cookie is dropped. Users will have to log in again the next time they visit your blog.