Archive for the ‘php’ Category

Setting up a scheduled event using the WordPress “Cron” functionality

Thursday, May 7th, 2009

The function reference for wp_schedule_event provides code examples for creating a plugin using WordPress’ “Cron” or scheduling functionality.

Hopefully this saves someone the few minutes it took for me to find this – pretty much everything you need to know!

Tip for Setting up Apache, MySQL and PHP on Vista

Monday, March 16th, 2009

Just setup a PHP/MySQL development server on my Vista-based laptop.

Here is a good rundown of setting up a VAMP (Vista, Apache, MySQL, PHP) server from Devshed:
Creating a VAMP

The other thing to know, which this article skipped, is that you should run your text editor as administrator when editing the config files. If you don’t do this you won’t be editing the correct file (only your Users version of it which isn’t actually used by the system).

Useful PHP Tools + Development Lessons from the PHP Masters

Friday, January 30th, 2009

Just came across a couple of great PHP-related articles.

50 Extremely Useful PHP Tools

It is a great list of PHP tools including: Debugging tools, Testing and Optimization Tools, Documentation Tools, Security Tools, Image Manipulation and Graphs, PHP Code Beautifiers, Version-Control Systems, PHP Online Tools and Resources, PHP Development Frameworks, IDEs and Editors, Firefox Add-Ons, and a bunch of useful useful extensions, utilities and classes.

10 Principles of the PHP Masters

Definitely worth a read for anyone doing PHP development regardless of the level. Here is the list

  1. Use PHP Only When You Need it – Rasmus Lerdorf
  2. Use Many Tables With PHP and MYSQL for Scalability – Matt Mullenweg
  3. Never, ever trust your users – Dave Child
  4. Invest in PHP Caching – Ben Balbo
  5. Speed up PHP Development with an IDE, Templates and Snippets – Chad Kieffer
  6. Make Better Use of PHP’s Filter Functions – Joey Sochacki
  7. Use a PHP Framework – Josh Sharp
  8. Don’t use a PHP Framework – Rasmus Lerdorf
  9. Use Batch Processing – Jack D. Herrington
  10. Turn on Error Reporting Immediately – David Cummings

I especially liked the discussion of 7 and 8.

Presentation by Manuel Lemos (PHPClasses.org) on Email Deliverability

Thursday, January 29th, 2009

Had a bit of a break from posting while I have been travelling with work. Back now and so should be posting a bit more regularly.

Found this great presentation today on Slideshare by Manuel Lemos of PHPClasses.org:
“Sending E-mail that reaches the destination using PHP”.

It provides a basic overview of email protocols and systems and covers best practices to ensure email gets through, including specific reference to PHP classes he wrote. The MIME Email Message Sending PHP Class is really useful.

Send SMS notifications from your Web Application

Wednesday, November 26th, 2008

A few years ago I started using Clickatell as a way to send SMS messages from different applications I built. Getting a message to notify you of particular events (“you received an order”, “something isn’t working right”) allows you to respond in a timely manner.

I have one web-based application that monitors various websites I work on and I get a downtime notification via SMS any time a site is down. I have also integrated SMS with osCommerce to send order notifications including the contents of the order. This is great for monitoring a low volume sideline store. There are lots of applications for this of course.

I have used Aleksandar Markovic’s Clickatell SMS API for a number of years. It supports CURL and fopen for the HTTP request and is very easy to integrate into your application.

GZIP compression not supported by WordPress 2.5+ (and what to do)

Tuesday, November 25th, 2008

I noticed that the GZIP compression option was no longer there in WordPress after version 2.5. This is recommended to be performed by the server now using mod_deflate.

If you don’t have access to mod_deflate, i.e. if you are on a uncooperative shared host, you can use this method using .htaccess …
Speed Up Your Blog Using ZLIB

If that doesn’t work you may be on a phpSuExec server. Create a file called php.ini in the root of your WordPress install with the following contents …

zlib.output_compression = On

You can test here:
http://www.gidnetwork.com/tools/gzip-test.php

Modifying WordPress Rewrite Rules – small problem + solution

Wednesday, September 3rd, 2008

add_filter('rewrite_rules_array','yourawesomefunction');

I had to look at the WordPress core code to work this out – thought I was going nuts. If you apply new rewrite rules using the rewrite_rules_array filter you need to ensure that you refresh the rewrite rules that WordPress has stored in a hidden option. You do this by simply resaving the Permalink Structure under the Options menu in the admin area of your WP install.

Not immediately obvious that this would be required, but makes sense that they generate the rules and store them at this point.

Implementing Free Geolocation with PHP Using Maxmind’s GeoLite Country

Sunday, August 17th, 2008

Need to serve up different content for people from different countries? Or track users by country? Or make a site more usable by providing options relevant to a particular country? I recently had a small programming task which required pre-selection of a country field based on the visitor’s country.

Maxmind offers a free Geolocation database, GeoLite Country which allows lookup of country from an IP. They claim it to be 99.3% accurate. They have a paid version that is more accurate. They also offer other databases, including one to lookup a city from an IP. The database is available as CSV data or in binary format. The binary format is very easy to implement as they provide APIs in a variety of languages. I used their PHP API. There are code samples to get things going quickly.

I used their PHP class which was the easiest to implement. Simply upload the class file and binary file and require the class file. The calls are simple and the lookup is fast. Very easy to implement.

Amazon’s Seller Central SOAP API

Tuesday, July 15th, 2008

Very disappointing experience working with Amazon.com’s Seller Central APIs. Their documentation is frankly very bad. Undocumented and incorrectly documented aspects will make the curve to get this working unnecassarily steep. Their support is not responsive. The forums are not overly helpful although you can see similar issues coming up. Disappointing for such a large and groundbreaking web-based company, especially as they are looking to promote their Web Services infrastructure to developers.

The comments in this article are very accurate of my thoughts/experience implementing Amazon’s Seller Central SOAP API using PHP (they are using Java) …

My time getting to the ‘hello world’ stage on this interface was measured in days vs minutes for pretty much every other system I have worked with.

Good notes on implementing Amazon’s Seller Central SOAP API

That article should help anyone regardless of the particular language they are using to do this. It helped me with one important final aspect that was undocumented by Amazon.

For more specific notes on doing this with PHP check out the last chapter of this book …

The Web Developer’s Guide To Amazon E-Commerce Service

A couple of key things in there will overcome issues with the particular way the Amazon SOAP server works. There will still be problems – but that will get you much of the way.

Note: don’t waste your time with Amazon AIM. As the article above mentions, unless you have an old account migrated from Amazon’s Marketplace system it will only work to download reports – it will not allow adding or updating products.

Great Article on Unicode and Character Sets

Wednesday, June 18th, 2008

It is easier as a developer who deals with English 99.9% of the time to overlook this stuff – especially in PHP – until you open and try to manipulate a bunch of .txt file not even thinking about the variety of Unicode formats. Found this rather enlightening …

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Good for any PHP coder to read, especially as the documentation on this stuff at PHP.net is a bit on the lean side.

Update:Character Sets / Character Encoding Issues from WACT with lots of PHP-specific information.