March 31, 2012

PHP vs. Frameworks

php logo square

Six years ago this month the Zend framework preview was released and Rasmus Lerdorf published a blog post titled “The no-framework PHP MVC framework” (italics added). R. Rajesh Jeba Anbiah noted irony.

August 7, 2011

PHPQuery

I have Matthew Batchelder to thank for introducing me to PHPQuery. I haven’t used it yet, but someday I’ll have need to select text elements from HTML using the PHP5 PEAR module. From the description “server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on jQuery JavaScript Library.”

Tags: , ,
May 13, 2011

This is how I did it

featured comment
April 5, 2010

Why PHP’s RegEx Is Slow, And What You Can Do About It (if you happen to be a committer on the PHP project)

Regular Expression Matching Can Be Simple And Fast, by Russ Cox: Perl [and PHP and others] could not now remove backreference support, of course, but they could employ much faster algorithms when presented with regular expressions that don’t have backreferences. How much faster? About a million times (no, I do not exaggerate). I use a [...]

May 5, 2009

Lessons Learned: Why It’s Better Not To Use Parentheses When They’re Optional

There it is in the PHP manual for return(): Note: since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case. I knew the parentheses were [...]

April 27, 2009

PHP Magic Constants: __LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, and __NAMESPACE__

I’ve been using __FILE__ for years, but I never thought to look for its siblings. I feel as though I should have noticed these earlier; they’re clearly referenced in the docs for debug_backtrace(), after all.

September 22, 2008

Scaling PHP

This two year old post about Rasmus Lerdorf’s PHP scaling tips (slides) is interesting in the context of what we’ve learned since then. APC now seems common, and it’s supposedly built-in to PHP6. Still, I’d be interested in seeing an update. Are MySQL prepared statements still slow? And that’s where Rasmus’ latest presentation comes in. [...]

September 14, 2008

Installing PHP APC On RHEL/CentOS

Yum up some packages: yum install php-pear php-devel httpd-devel Install APC using pear (the pear installer is smarter than the pecl installer): When the installer asks about APXS, say ‘no’.  pear install pecl/apc Tell PHP to load APC: echo extension=apc.so > /etc/php.d/apc.ini Restart Apache: /sbin/service httpd graceful

August 16, 2008

Mark Jaquith On WordPress Security For Plugin Developers

I’ve been pretty aware of the risks of SQL injection and am militant about keeping my database interactions clean. Mark Jaquith today reminded me about the need to make sure my browser output is filtered through clean_url(), sanitize_url(), and attribute_escape(). Furthermore, we all need to remember current_user_can(), check_admin_referer(), and nonces.

August 7, 2008

Is My PHP Script Running Out Of Memory?

I’ve got a PHP script that sometimes just dies with no errors to the browser and no messages in the error log. I’ve seen this in the past with scripts that consumed too much memory (yeah, it should have issued an error, but it didn’t, and increasing the memory limit fixed it), but now the [...]

July 15, 2008

Web Development Languages

David Cloutman pointed to Craiglist’s job ads as an indicator of programming language popularity. Here’s the hit counts for “web design jobs” and “internet engineering jobs” in the Bay Area:   PHP Java Ruby Python PERL internet engineering jobs 167 246 85 98 109 web design jobs 110 71 22 19 31 Cloutman has a [...]

May 28, 2008

JSON on RHEL & PHP 5.1.6

Stuck with PHP 5.1.6 on RHEL or even CentOS (and a sysadmin who insists on using packages)? Need JSON? I did. The solution is easy: yum install php-devel pecl install json The pecl install failed when it hit an 8MB memory limit, and I was clueless about how to fix it until I learned that [...]

March 4, 2008

Parse HTML And Traverse DOM In PHP?

I spoke of this the other day, but now I’ve learned of PHP’s DOM functions, including loadHTML(). Use it in combination with simplexml_import_dom like this: $dom = new domDocument; $dom->loadHTML(’<ul><li>one</li><li>two</li><li>three<ul><li>sublist item</li></ul></li></ul>’); if($dom){ $xml = simplexml_import_dom($dom); print_r($xml); } This IBM developerWorks article has some more useful info.

March 3, 2008

Parse HTML And Traverse DOM In PHP?

I love how easily I can traverse an HTML document with jQuery, and I’d love to be able to do it in PHP. There are a few classes, but the PHP binding for Tidy seems to be where it’s at. The Zend dev pages make it look that way, anyway.

January 24, 2008

Apache, MySQL, and PHP on MacOS X

p0ps Harlow tweeted something about trying to get an AMP environment running on his Mac. Conversation followed, and eventually I sent along an email that look sorta like this: If you’re running 10.4 (I doubt it, but it’s worth mentioning because I’m most familiar with it), here’s how I’ve setup dozens of machines for web [...]

January 17, 2008

sifting results of error_log( …

sifting results of error_log( $_SERVER[’REQUEST_URI’] ."\n". $_SERVER[’REMOTE_ADDR’] ."\n". print_r( debug_backtrace(), TRUE ) );