A Symfony Plugin for Generating Charts using Googles Visualization API (sdInteractiveChartPlugin)

Last week I released the first (beta) version of my interactive charting plugin for the Symfony PHP framework. It is currently only version 0.1.2 so it’s a bit rusty round the edges, but over the next couple of weeks I will be improving it and adding extra functionality to it. I also intend to package up another version (which I will host on my blog) for anyone not using Symfony to use in there PHP projects. Below are just a few details on the plugin:

UPDATE: The plugin has been updated to version 0.2.0 (Available on the Symfony website), more of the APIs options have been implemented along with an improved callback function and more streamlined code.


The plugin allows you to insert Javascript powered charts into any page of your site without writing any Javascript. It is especially useful when the data for the chart and possibly even the type of chart is based upon an authenticated users preferences (i.e. creating different charts for each user). The plugin handles the loading of the required libraries and creation of the correct chart object as well loading the data in via AJAX if you want. It also helps to keep your HTML page code as neat and tidy as possible by only writing exactly what’s needed into the dynamic page and storing all the rest in a general JS file which is the same for all users.

Chart Types:

It can create a number of different charts:

  • Area Charts
  • Bar Charts
  • Column Charts
  • Gauges
  • Line Graphs
  • Pie Charts


Head to: http://www.symfony-project.org/plugins/sdInteractiveChartPlugin

Connecting to an Amazon RDS via PHP

If your trying to connect from an Amazon EC2 instance to an RDS instance in PHP and finding that the connection keeps timing out (i.e. you get a mysql 2003 error). try using the IP address for the RDS instance instead of the hostname (or ‘Endpoint’ as Amazon calls it).

So instead of using:

$link = mysql_connect('mydbinstance.c7hszkfowzmc.us-east-1.rds.amazonaws.com:3306', 'mysql_user', 'mysql_password');

Use something like this (obviously replacing the IP address below with the IP of your RDS):

$link = mysql_connect('', 'mysql_user', 'mysql_password');

Changing PHP settings with FastCGI and suPHP

Recently I needed to change the upload_max_filesize for php running on one of my sites. As this can only be done in either .htaccess (when running php as an apache module) or using php.ini, I was forced to use the php.ini method.

So I created a new php.ini file and added the following lines:

upload_max_filesize = 32M
post_max_size = 64M

The post max size all ways needs to be greater than the upload max filesize other wise the upload max filesize can never be reached as it will get limited by the post max size before hand. Uploaded this to the server and I a look at the phpinfo() output. But still the post_max_size was set to 2MB.

After scouring the internet for quite a while wondering why my php.ini file was not being picked up by php running in FastCGI mode I finally discovered I had to add an extra line into my .htaccess file to tell suPHP where to find my php.ini file.

I opened up my .htaccess file directly under my web root and added the line:

suPHP_ConfigPath /<path to my public_html>/public_html

And like magic PHP picked up the new php settings and the upload_max_filesize went upto 32MB.

I hope this helps someone else having the same issue solve it far quicker than I did.

Changing The Page Position of WordPress Pages & Categtories

I decided it would be better if I had my list of pages for my new shiny blog along the main navigation area (under the title) instead of hidden away at the top of the page! So… In case anybody else wants to do the same thing I will tell you how!

Edit the file: wp-content/themes/<Your theme’s name here>/header.php

NOTE: you can either do this in your favourite text editor OR in the WordPress admin area, under Appearance > Editor

Scroll down and find the line that goes something like this:

Then find the line that goes like this:

Now if you want to swap your pages with your categories simply swap the two lines above over… Ooo an remember to save.

In my case I wanted to remove the list from right at the top of the page as I added a category widget to the right hand side of my blog (as you may have noticed), so I removed the code that went: “wp_list_categories” altogether.

That’s it… refresh your browser and like magic your list of blog pages will now be where the list of categories used to be.

Comparing preg_replace and str_ireplace (Rude Word(s) Filter)

Filtering users input is unfortunately something that needs to be done these days. Possibly even more so when the content is coming from another website/service (such as twitter or facebook).  Swearing/rude words is quite a serious area, as you really don’t want to offend any visitors to your site by displaying a live thread showing comment or a ‘tweet’ or similar containing offensive langauge (tends to go down badly). So on this very note I set out today to add a live twitter feed to my current project (www.wsaf.co.uk), but decided once I had pulled the data from twitter I should probably remove any swearing before displaying it on the site!

As the site is written in php funnily enough this was also going to be. As I like to make my code as fast a possible I decided I would test the speed to different functions that could be used for this purpose:


Continue reading