Category Archives: Uncategorized

RabbitMQ hanging on publishing to queue

Are your scripts hanging when trying to publish to the queue?

Just had this issue so wanted to add a quick entry. Trying to enqueue a message into rabbitmq suddenly started failing. It was working yesterday, WTF? After breaking down the script and running it line by line; create connection, check; create channel, check; create exchange, check; create queue and bind it to the exchange, check; publish to exchange…. check; do anything else after that point, fail.

Publishing acted like it was working, but nothing got into the queue. Trying to close the connection at that point would hang. No exceptions thrown and returned true, as in all hunky dory.

Fired up the gui interface and there it was. Disk space surprisingly low. Oh theres that 18gig log running in verbose mode. Kill. Rabbitmq works again, yay!

PGSQL Driver Mismatch

PDO: driver pgsql requires PDO API version 20060409; this is PDO version 20060511

The above error was the final roadblock in getting one of our servers back into working condition after a server upgrade. I am posting this here because it took a very long time to discover a solution and I found the solution on a site in German. Thank you google translate.

In short, this server is a combination of PHP, Lighttpd and PGSQL. After the update Apache tried to run at startup and I had to remove the links to the Apache startup scripts found in /etc/rc*.d. A few more step to clear a Lighttpd warning about ipv6 and then I tried to start Lighttpd, /etc/init.d/lighttpd start. That’s when the above error reared its ugly head.

Some generic searches gave some results, but nothing that said “do this to fix it”. Until I slapped the error in google word for word and found a handful of Chinese and German pages talking about it. Fixing this issue ultimately required upgrading PDO and its PGSQL module and that looked something like this:

  1. pecl uninstall pdo pdo_pgsql
  2. pear upgrade PEAR
  3. pecl install pdo pdo_pgsql

Start Lighttpd and life was back to normal!

Setting Up Paypal IPN, Trials and Tribulations

Getting Started

This PDF File is a great place to start.

It will show you how to set up IPN notifications, what to expect from paypal, the process to verify the notification and even gives you some sample code.

IPN, while not required, is a great way to know when you’ve actually gotten paid. This way you don not have to sift through the mountains of emails of profile creation, payment reversed, payment canceled, payment completed, etc. Getting the IPN that says Complete lets you know to make a shipment because you’ve actually gotten paid. At least in theory.

Example Code

The example code provided by Paypal is written in PHP and is a good starting place.

I’m repeating it below, for the most part, with my modifications to ignore IPN notifications I don’t care about and to use CURL instead of fgets

Testing

There are two ways to test before pushing up to production which ultimately leads to the problem. You can force an IPN to be sent to you through the sandbox with 100% test data or actually do a test purchase.

Following the code provided leads to the issue. The forced test IPN works quite nicely; you get it, send it back and Paypal says VERIFIED every single time. Doing a test transaction however returns INVALID without fail.

I found the solution on this site. The long and short is there is a carriage return between address line 1 and line 2 that paypal represents as %0D%0A but is represented as %0A in PHP 5.2.

So below is what I hope is simplified code, assumes you have magic quotes turned on, uses curl and has the carriage return fix:

  1. <?php
  2. $PAYPAL_URL = “https://www.sandbox.paypal.com”; //or https://www.paypal.com
  3. $PAYPAL_EMAIL = “your_email@gmail.com”; //usually your login email
  4.  
  5. if($_POST[‘txn_id’] && $_POST[‘receiver_email’] == $PAYPAL_EMAIL){
  6. //Check for Primary PayPal email, also ignores profile creation IPNs, just care about payments for now
  7.  
  8. $url = “$PAYPAL_URL/cgi-bin/webscr”;
  9. $http_status = 0;
  10. $params = “cmd=_notify-validate”;
  11.  
  12. foreach ($_POST as $key => $value){
  13. $value = urlencode(stripslashes($value));
  14. $value = preg_replace(‘/(.*[^%^0^D])(%0A)(.*)/i’,’${1}%0D%0A${3}’,$value);//return fix
  15. $params .= “&$key=$value”;
  16. }
  17.  
  18. $response = http($url, $http_status, $params);
  19. if($response == “VERIFIED” && $http_status == 200){
  20. //Check that txn_id has not been previously processed
  21. //Process the IPN recieved based on the payment_status
  22. }
  23. else{
  24. //store for further investigation or ignore
  25. }
  26. }
  27.  
  28. function http($url, &$http_status, $post_data){
  29. $ch = curl_init();
  30. if (defined(“CURL_CA_BUNDLE_PATH”)) curl_setopt($ch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH);
  31. curl_setopt($ch, CURLOPT_URL, $url);
  32. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  33. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  34. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  35.  
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  37. if (isset($post_data)){
  38. curl_setopt($ch, CURLOPT_POST, 1);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  40. }
  41. $r = curl_exec($ch);
  42. $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  43.  
  44. curl_close ($ch);
  45. return $r;
  46. }
  47. ?>

March ’09 Monthly Faves

More faves for the month. Some of these were written in February, but I didn’t stumble across them until March.

Lay Off the Juice Man!

An article running down the debacle that was the Tropicana carton redesign. Lots of good links and a particularly good quote from Paul Ford.

Creativity Abound

Designers block? Spark your creativity here. Lots of good examples and links.

Building Your Own Portfolio?

Ten surprisingly good things to consider when designing your own portfolio. Followed up by a slew, too many to count, of great portfolio examples.

Monthly How To

In this months how to segment we learn how to create simple and elegant light streaks using Photoshop. Thank you SpoonGraphics for being so awesome.

Manage A Large Corporate Site?

Learn what your corporate site is doing wrong, along with a slew of other things management will never give you the go ahead to fix.

Monthly Faves

In an effort to provide more content I plan on doing these monthly faves posts. Mostly centered around web design and practices, but not always as my interests tend to wonder every now and then.

50 Dollar Logo Experiment

According to Forbes design is a snooty business and instead you should use sites like CrowdSpring to allow 10,000+ designers who know absolutely nothing about your business and are just looking to get paid to design your logo/print/site for you. They do guarantee quality and at least 25 entries so how can you go wrong? In all reality it is the designers that are hurting themselves by participating. Lets move the industry forward with grace and quality, not backwards with design by committee and spec work. But hey, if you’re interested fire up your browser hit iStock photo and become a designer!

Over here off my soap box, this link is an example experiment with one of the instant, cheap logo design adds (similar to clownSpring) you get if you google logo design.

iPhone Browser Simulator

Just a nice way to view your site on the iPhone. Requires Safari 3.2 for windows and has only been tested on Vista.

Learn Blender

Ever since the first time I played with Maya and LightWave I’ve wanted to someday return to the world of 3D modeling. However, the price tags on these things are a little steep to just play around with. Blender on the other hand has the very attractive free price tag.