Tag: PHP

  • Amazon Links

    Astute readers will notice that I now have Amazon related links (books, actually) on some entries (spun out of my Amazon’s Web Services post). Hopefully they’re not too intrusive; I have them limited to a max of three results right now, and they’ll only show up on blog entries that I specifically keyword.

    All done with Amazon’s web services. It’s not completely automatic, since I have to keyword the entry, but it beats looking up items by hand. Using the web service interface is extremely easy; simply build a URL and send the request to Amazon, and you’ll get XML results. I’m using the excellent Snoopy PHP class for the communication piece, and PHP’s built in XML parsing (using expat) to extract the information I want from the XML.

    Some tips, after trial-and-error: Use a “Power” search in the Amazon request, especially if you have multiple keyword sets. An example might look like:

    Power=keywords:(web services) or (xml) or (http programming)

    The regular “Keyword” search turns useless after four or five words, it seems, and the “TextStream” search returned totally random results.

    I played around with have the results sorted by rating (“reviewrank”), but dropped this because I was finding that older editions of the same book (hardcover vs. paperback, for example) might have a higher rating, but not actually be available. By dropping the sorting entirely, Amazon returns surprisingly relevant results.

    The results can include images, all hosted on Amazon’s servers. Use them! They come in three sizes.

    And finally, pick your keywords carefully. Or you’ll get some weird, totally unrelated items.

  • php|tropics

    A bit over a year ago I blogged about the PHP Cruise. Well, this year there’s another PHP conference organized by the folks at php|architect, though it’s not a cruise this time: php|tropics!

    It’s in Cancun, Mexico, from May 11 through 15. Now, if I only had a few grand lying around and could convince work that it’s a business trip…

  • PHP Suggest

    Over on php.net, they announced a full implementation of a search field suggestion box:

    The function list suggestions we started to test a year ago seemed to be working better as some bugs were found and fixed, so it was time to make the result available on all php.net pages.

     

    Whenever you type something into the search field, while having the function list search option selected, you will get a list of suggested functions starting with the letters you typed in. You can browse the list with the up/down keys, and you will be able to autocomplete the function name with the spacebar.

    Couple things I find interesting about this. First, it predates Google Suggest by a year (prior art that everyone heralding Google Suggest seemed not to notice); did Google get the idea from the PHP site, or is this more common?

    The second point is a bit more trivial, but I noticed when I was trying it out by typing in “date” that there are two additional PHP date functions that appeared in the list: date_sunrise() and date_sunset(). These are new to PHP 5. They take a timestamp, latitude, and longitude and return the respective time of day for sunrise or sunset. What’s interesting is that they are remarkably similar to two functions I had written well before PHP 5 came out. (“Written” is subjective, more like “adapted,” probably from a Java function somewhere.) However, from the looks of the manual, these new built-in functions only take a Unix timestamp, which limits the results to dates between 1970 and 2038, while my functions take any combination of month, day and year. The point? I just like to toot my own horn sometimes. :)

  • PHP code rant

    This is a mini-rant on PHP that can be safely avoided by non geek types.

    This post over on PHP Everywhere caught my attention, vis-a-vis programming semantics and practice. Basically, inside a switch statement, someone placed the default block before the case blocks and was surprised when that default condition executed, and the “expected” case did not.

    Some are calling this a bug; I do not. This is the exact behavior I expect switch and default to display, and I always place any default blocks last in the statement, because that makes the most sense semantically and logically. I expect this because that’s how I learned it when learning C years ago; it’s the way the switch construct works and why it’s so fast.

    Relevant snippage from the PHP manual:

    The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don’t write a break statement at the end of a case’s statement list, PHP will go on executing the statements of the following case….

    A special case is the default case. This case matches anything that wasn’t matched by the other cases, and should be the last case statement.

    Seems pretty clear to me. I would expect PHP to immediately execute the default block as soon as it encounters it, even if this “cuts off” remaining case blocks below it. So quit complaining and write cleaner code.

    Okay, done ranting.

  • Friendster goes PHP

    An item I saw yesterday but forgot to blog about: Friendster goes PHP. Pretty cool.

    Finally on Friday we launched a platform rearchitecture based on loose-coupling, web standards, and a move from JSP (via Tomcat) to PHP. The website doesn’t look much different, but hopefully we can now stop being a byword for unacceptably poky site performance.

    I haven’t had much of a chance yet to use Friendster to see if it truly is faster, so I can’t personally comment on that aspect. And predictably, this is going to bring all sorts of people out of the woodwork arguing over the relative merits of Java/JSP (which was old Friendster) versus PHP… just look at the comments on the link above to see it already happening. And while debate and disagreement can be healthy and productive, how about a quick reality check to everyone:

    PHP is good. Java is good. Both have their merits and disadvantages. Loudly complaining that [Java|PHP] is the only true way and the other is crap is boring and uninformed.

  • MT Comment

    What with the current brouhaha over Movable Type‘s licensing and payment scheme for the version 3 software (what, you want a link? Feh, go Google it), all I can really say is, damn it’s sure handy to have written my own system. :)

    I notice that a lot of people are seriously considering migrating to WordPress. That’s cool, it uses PHP and seems pretty solid.

  • Conspiracies in Web Tracking

    Despite my headline, I’m not really going to go all Mulder on you and start ranting about Big Brother and privacy issues and all that. Instead it’s just some thoughts I’ve been entertaining lately on technology and tracking people and habits on the Web. Some people may choose to see the things I’m writing about as conspiratorial, and that’s fine for them; they may not want to read on, though :) . (more…)

  • Searching and Minimum Word Length

    Mike Boone, in the comments section of yesterday’s entry on searching (“Updated Search“), correctly points out that searching my site for a word that is less than four characters in length (like “php” or “cow”) does not work—no results are returned. Obviously, since I write about PHP on occasion, this is untenable.

    The problem is that MySQL‘s fulltext indexing, by default, only indexes words greater than three characters long, and I don’t think I have any way to change this, despite my initial reply to Mike’s comment. This site is running on a shared server setup on pair.com, and I have absolutely zero control over the MySQL server configuration. I might post a question to their tech support, but I’m not overly optimistic about the response. So, what to do?

    Short term, here’s my solution (though it’s not implemented yet): examine each word in the search string, throwing out stopwords (like “the,” “and,” “so,” etc.), and for any word shorter than four characters long, do a LIKE search against the content for them. No, it’s not ideal, but it’s a patch. Comments?

  • PHP Development Hint

    Here’s a general hint for PHP development: A quick and easy way to check for syntax or compile errors without uploading the PHP script to the Web server and testing online through a browser is via the command line. It’s obvious, and I don’t know why I didn’t think of this sooner, but I’ve been doing more and more of it lately.

    I develop primarily under Windows (with PHP installed) and upload to a Unix-variant server, and this what I’ve been doing to run a PHP script on the command line on my Windows system:

    php-cli -l filename.php

    You could omit the -l option (it’s a syntax check option only) to parse and run the code, if you like. Either way, it’s an easy way to check your code without uploading it and potentially breaking your site.

  • Rasmus is the Man

    Rasmus Lerdorf, that is, the creator and godfather of PHP. He’s got an article on the Oracle Technology Network titled “Do You PHP?” that’s definitely worth a read. Here’s a sample:

    What it all boils down to is that PHP was never meant to win any beauty contests. It wasn’t designed to introduce any new revolutionary programming paradigms. It was designed to solve a single problem: the Web problem. That problem can get quite ugly, and sometimes you need an ugly tool to solve your ugly problem. Although a pretty tool may, in fact, be able to solve the problem as well, chances are that an ugly PHP solution can be implemented much quicker and with many fewer resources. That generally sums up PHP’s stubborn function-over-form approach throughout the years….

    Despite what the future may hold for PHP, one thing will remain constant. We will continue to fight the complexity to which so many people seem to be addicted. The most complex solution is rarely the right one. Our single-minded direct approach to solving the Web problem is what has set PHP apart from the start, and while other solutions around us seem to get bigger and more complex, we are striving to simplify and streamline PHP and its approach to solving the Web problem.

    The guy just oozes common sense. Here’s another bit about PHP that he wrote on the PHP-DEV mailing list about two years ago, one of my favorites that just sums up beautifully the philosophy of PHP:

    The golden rules of PHP are to keep the WTF(*) factor low and the POTFP(**) factor high.

    (*) What The Fuck
    (**) Piss Off The Fewest People

    No two ways about it: he’s one of my heroes.