Friday, November 30, 2012

PHP cURL Emulator

Yesterday I ran into a problem trying to implement Sign In with Twitter using PHP. I had implemented the feature and got everything working good, but after I deployed it out to my production server it wouldn't work. The sign in process would just halt dead in the tracks. Took me a while to figure out why - the OAuth library I was using made use of the cURL PHP extension. As it turns out, the production PHP server this was running on was configured with the '--without-curl' flag, so curl_exec would just fall flat on its face.

After talking with the sysadmin for that server, and being told that there was no chance of recompiling the PHP installation on the server in order to enable this feature, it was back to the drawing board. Unfortunately, after a bit of research, I found that every single Sign In with Twitter PHP library uses cURL. Every one.

Then, luckily, I found the most wonderful little PHP library that acts as a cURL emulator. It is from a site called Blitzaffe Code. After adding the files to your project, you simply include a single php file into your source code, and you are then guaranteed some sort of cURL support, regardless of where you run your code.

It will first try to use the standard cURL extension, and if it is available then this library does nothing. If it isn't available, it next tries to use the command line version of cURL. If that is also unavailable, it finally falls back on its own pure PHP implementation of the cURL methods.

After I added this into my source and redeployed to production, everything worked great! It was a real life saver, so I thought I would pass along a shout out to them.

You can get the library from here:

No comments:

Post a Comment