php

Install PHP XDebug via Pecl

Even though you may find xdebug in a yum repository, due to version incompatibilities you may need to compile/install it using Pecl. Following are several easy steps to achieve exactly that:

> pecl install xdebug

check the output of the command above, if everything went well, you should see something like :

Installing '/usr/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.0.5

at the end of the output. Note the location of the .so file and using it create /etc/php.d/xdebug.ini file that rads something like:

; Enable xdebug
zend_extension="/usr/lib64/php/modules/xdebug.so"

Once you are done with the installation, restart Apache and check the PHP module list with: "php -m", you should see "xdebug" appear in the list.

Sane Backtrace in PHP

PHP error messages are quite helpful, most of the time. Sometimes they do fall short of telling us what went wrong, however. It's especially common when and if you use a development framework (e.g. Drupal). Frameworks often do output buffering and/or code eval()-ing, making debugger output incomprehensible.

In such cases PHP's debug_backtrace() function is a real savior. debug_backtrace() is also very helpful if you want to look at the execution stack in a complicated code, to better understand the code. This function shows the execution stack that lead to the current function and does it pretty well... "too well" sometimes :) Out-of-the-box version of the function shows the list of invoked functions, source files they belong to, line numbers in the source file and the argument values being passed. The latter can be a huge problem, if code is passing around large variables. Output on the screen may get so garbled (esp. if HTML is used in variables) that the entire exercise may lose its meaning.

Short snippet below sanitizes debug_backtrace() output to make it slimmer and more comprehensible:

$trace = debug_backtrace();
foreach ($trace as &$t) {
  unset($t['args']);
}
echo "<pre>".print_r ( $trace,true)."</pre>";
exit();

Teaching Espresso Drupal PHP file Extensions (e.g. .module)

UPDATE: a much better/easier way of achieving the same is now available. Read more at: http://www.freshblurbs.com/adding-drupal-django-and-jquery-support-espre...

Espresso From MacRabbit (you may remember them for their splendid CSSEdit eidtor) is a new Web editor, for Macs, worth paying attention to. It handles the usual suspects: PHP, CSS, HTML, servers over SFTP, Amazon S3 etc with style out of the box and has numerous extensions for other things like Python, LUA, SQL, Regular Expressions etc. And it's only 1.x version, so you bet you can expect much more in coming versions.

One little shortcoming it had, for Drupal developers is that, there's no easy way to configure custom-for-Drupal PHP extensions: .module and .install to make Espresso recognize these as PHP files.

Joe Shindelar of Dreamformula has posted a nice blog post detailing the configuration of custom PHP extensions in Espresso.

Thank you, Joe!

Install PHP 5.2 on CentOS 5.2 Using Yum

Yum is a standard installation utility for CentOS 5.2. One of the reasons I favor CentOS over other Linux distros is actually because it comes with yum. It is that good!

Unfortunately, CentOS 5.2 does not generally include the latest versions of libraries, because it follows conservative path of the RedHat Enterprise. Which is not that bad of an idea, for a server OS... until you need that latest version of something and you are stuck... or: not necessarily.

If you a are a Drupal developer, there's a very good reason why you need the latest version of PHP: 5.2. The reason is called FileField module. This module is required by another absolutely essential module ImageField making it a matter of life-or-death (just kidding) to have PHP 5.2 on your server. But the latest CentOS release (ironically also 5.2) only comes with PHP 5.1.6.

What to do?

Drupal Theme Developer's Cheat Sheet

A very handy PDF with a list of variables available when themeing Drupal: Download PDF

The Best SFTP Plugin for Eclipse

The best and, honestly, the only usable SFTP and/or FTP plugin for Eclipse is Target Management. This plugin makes over-the-SSH development in Eclipse a practical possibility.

One of the greatest features of this plugin is that it allows working with files, without creating a project, something that vanilla Eclipse is insanely paranoid about. Out-of-the-box Eclipse forces you to first create a project. As a consequence, even if you map a remote server as a network drive, over SSH, you may still have problems working in Eclipse. Reason being - Eclipse constantly analyses project files and over SSH it is just too darn slow.

You can use Target Management for local development, too, if you hate creating projects. Actually, it makes sense for PHP development. Whilst Java developers always think in terms of projects and dependencies (guess why - they need to build the darn thing), PHP developers do not have to carry the same burden and may choose to avoid the overhead. By the way - if you are using Eclipse for PHP, you definitely need to install PDT plugin and the easiest way is to install a pre-built, "bundled" version that you can find on the PDT download page: [http://download.eclipse.org/tools/pdt/downloads/]

If you are serious about using Eclipse as your IDE, you definitely need this plugin.

Please note that you have to install CDT plugin, before you can install Target Management. Also, CDT is not part of standard Eclipse distribution so you need to add the update site, just "install required" will not help. The update URL for CDT is: http://download.eclipse.org/tools/cdt/releases/europa

When you are done installing TM, add its primary view to your perspective via:
Window -> Show View -> Remote Systems
and start enjoying.

Del.icio.us Tag Filtering in PHP/Drupal

Filtering content through URI tagging was initially popularized by Del.icio.us and is now a common way to quickly navigate content. For instance, in a system that supports this type of navigation, you can constract a URL:

http://example.com/tag/drupal+news,rss

and get a vertical view of the domain data. In this markup, "+" stands for logical AND, whereas "," stands for logical OR.

Following is a PHP code snippet that processes "delicioused" query string into a logical expression (you can modify the code slightly and get an SQL where clause instead). In addition to the original del.icio.us syntax, it allows tags with spaces in them. You just need to enclose those in single or double quotation marks. For instance, the following expression is a valid one: http://example.com/tag/drupal+news,rss,'Steve Jobs'. Note: using quotation marks inside the tag names is still invalid syntax!

And following is the code sample:

Basic PHP Logging

One of the most powerful ways to debug a web application is using logging; especially for a highly complex system like Drupal. PHP comes with a built-in logging function: error_log();. The exact behavior of this function depends on several configuration parameters.

We suggest that you log into standard Apache error log and create one log per virtual host. To achieve this, make sure that in php.ini you have "error_log = " directive commented-out, so that PHP does not log either in one specific file or syslog, and also make sure you have "log_errors = On". In addition, in httpd.conf (or wherever you have virtual hosts configured in Apache) for the virtual host configurations, make sure you have separate log files per a Virtual Host with a directive like: ErrorLog logs/buzzmonitor.log

The basic logger is not as powerful as the PEAR logger, but is much safer. If you use PEAR logger, you must be sure that anywhere your code will be installed, PEAR Log module will be installed, too. That is not a safe assumption, especially for Drupal developers that publish their code in open-source.

Beware: eAccelerator and PHP ZLIB Compression

On numerous LAMP servers we run, we repeatedly experienced an odd and disturbing problem. Users were fed some "random" ASCII text, instead of a rendered page, leaving them in complete frustration. After rigorous investigation, we came to a conclusion that the problem lies in a combination of PHP's zlib compression and eAccelerator. The odd part that greatly complicated debugging was that only some users experienced the problem.

eAccelerator is a "free open-source PHP accelerator, optimizer, and dynamic content cache". It's also one of the most widely used and stable implementations. The performance gains from eAccelerator are very imperssive, especially since there is no code-change involved and cache is transparent - data is real-time.

zlib comperssion is a PHP feature that compresses output (pages) and can significantly decrease both traffic usage, as well as page load times.

Unfortunately, the two do not work well together.

The Best PHP IDE for Windows

I am always on the lookout for good IDEs, including the ones for PHP. There are several decent ones on the market. From the open-source ones, Eclipse with PDT does a decent job, for local development, if you do not mind extra weight of a JDK-based IDE. It has some other issues as well (poor support of on-the-server development via SFTP and forcing the use of pre-configured projects are a few), but Eclipse is not what we'd like to discuss in this post, today.

Today I stumbled upon a new (for me) Windows-based, PHP IDE: EngInSite PHP IDE and I was, quite frankly, blown away! EngInSite is, quite simply, the best PHP IDE on a Windows platform. I have been playing around with it for a couple hours now and I have to yet find a feature I would like that it does not have. It's a very rare example of a perfect tool.

Few important features from the long list of this IDE's capabilities:

Syndicate content