Posts Tagged ‘php’

Using the PHP PEAR Services_Twitter Package with HTTPS

Saturday, January 25th, 2014

I have a PHP script that runs every few minutes via a cron job that has been running for a few years to send me direct messages on Twitter from a single-purpose Twitter account. The net result is that I can have system alerts sent to me by text message (by having direct messages from this special account subscribed for mobile alerts).

This script stopped working a week or two ago, and I finally got around to figuring out why. On Jan. 14, 2014, Twitter made SSL/TLS mandatory for connections to api.twitter.com. The announcement / blog post about that is here: https://dev.twitter.com/discussions/24239

Apparently, and not surprisingly, the PEAR module, Services_Twitter (available here: http://pear.php.net/package/Services_Twitter/),  works with api.twitter.com, and thus stopped working.

The fix was simple, once I was able to decipher the automated docs…

After this line: $twitter = new Services_Twitter();

I added this line: $twitter->setOption(‘use_ssl’,true);

The placement is probably flexible. But this one line worked. And my phone is now getting all those text message alerts that I dread. Yipee (?)

I wonder if I’m the only person using this library, considering that my Google searches came up surprisingly sparse on this topic…

 

 

Contact Us Through our New Contact Form on perceptus.ca

Sunday, January 9th, 2011

We did a largish update to our corporate homepage, perceptus.ca.

There are little changes here and there such as a new background graphic, some updates to the copy, and some changes to the layout.

The most important bit, which really was the catalyst for the change, was our  new contact form, complete with reCAPTCHA to keep the spam to a minimum.  The contact form is actually a test page for us, it’s designed to be highly portable, and you’ll see it on most of our critical websites very soon.

We might even publish the class file – it is far  better than the top few  contact form scripts in PHP that turn up on a search on Google.

PHP PEAR HTML_Template_IT Eats Dollar Signs

Wednesday, December 29th, 2010

Sigh.  We discovered a bug in our recently reworked tools.perceptus.ca (“PWT”) site.

We have a simple, custom, partial MVC system that runs a few of our smaller websites.  That system uses the PEAR HTML_Template_IT package to do the final template rendering. We ported PWT to our MVC to make future site changes much easier.

A week after going live with the changes, we found a baffling bug.  The tools were eating the dollar sign and dollar amounts (but not the decimals) from the input text. E.g. “$103.00” would get returned as “.00”.  Not good.

Apparently, HTML_Template_IT defaults to processing all text with regex.  Not cool.

There might be a historical reason for this, but for new users, this has got to be confusing. Plus, this is NOT mentioned in the intro documentation: http://pear.php.net/manual/en/package.html.html-template-it.intro.php

We’re not the only ones caught by this: http://pear.php.net/bugs/bug.php?id=50.

The fix is to initialize and set the use_preg option, like this:

$tpl = new HTML_Template_IT(‘./’,array(‘use_preg’=>true));

I have glanced at the package pages, and while this behavior is  documented it is buried quite deeply in the documentation.

This also explains a typo we had years ago on a static page that had the text like $5 in it.  That time, we just changed the copy to read 5 dollars and got on with life.

 

How I had to fix PHP PEAR

Monday, March 10th, 2008

I’ve always found the code libraries of PHP PEAR to be quite useful.

But the PEAR website and individual package documentation is often baffling. I wish users could contribute comments and sample code easily, like the online documentation of PHP.

On to today’s rant. I just upgraded the Linux distribution that runs my home server to SME7, see contribs.org. Since it’s based on Red Hat Enterprise Linux, it comes with an old version of PHP Pear. Out of the box, it does not work. This is OK. On the frontpage of pear.php.net homepage the reason is clearly posted:

“[January 3, 2008] As promised, XML-RPC has been disabled at pear.php.net.”

The news post tells you how to update older installs of PEAR to work with the new system. That would be fantastic, if the instructions worked.

But they don’t. At least for older than expected versions of PEAR.

Fortunately, I have notes from earlier this year on another server upgrade I did.  I had to search high and low to get my old version of Pear working. Earlier this year, I run these commands to upgrade and fix PEAR:

pear upgrade –force http://pear.php.net/get/Archive_Tar http://pear.php.net/get/XML_Parser http://pear.php.net/get/Console_Getopt-1.2

(note, that’s all one command up there)

pear upgrade –force http://pear.php.net/get/PEAR-1.4.3.tar


pear upgrade PEAR

The difference is the Console_Getopt-1.2 line. It specifies the exact version of the Console_Getopt package to install. Shrug.

Today, I had an extra step:

On the second command, the PEAR-1.4.3.tar one, I go this error:
requires package `PEAR’ >= 1.3.3

I guessed that I needed to do a half-step upgrade first… i.e.
pear upgrade –force http://pear.php.net/get/PEAR-1.3.3.tar

Then do the original line:
pear upgrade –force http://pear.php.net/get/PEAR-1.4.3.tar

Then the final upgrade:
pear upgrade PEAR

I don’t know why PEAR had to disable the XML-RPC interface.  I don’t really care.  But I do find it annoying when the instructions on the front page of a site don’t work.

This problem will affect other people besides me. This will probably hit everyone else who is installing a new RHEL4 (or derivative) server. Long life distributions with non-functional PHP PEAR software will be kicking around for a few more years.

I’d post this on the PEAR Wiki. But there is none. Fortunately, this blog gets indexed by the search engines, so maybe it will prove useful to someone other than me.