php

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:

Line Delimiters in Eclipse

Eclipse is an IDE of choice for many. It's been very popular among Java developers for a long time, but lately it is getting some traction in the PHP world, as well. A big contributor has been the absolutely fabulous Eclipse PDT project that makes Eclipse PHP-intelligent.

Whether you are developing in Java, PHP or any other language Eclipse supports, you most probably have to deal with cross-platform issues. One of the most trivial, yet annoying is the matter of line-delimiters. For whatever historical reasons Windows, Unix/Linux and Macintosh use different delimiters. It almost makes you wonder if the creators of the three major operating systems were sadistic enough to intentionally employ all three possible variations to make our lives more difficult.

Install PECL Memcache with XAMPP and PHP4

XAMPP is an absolutely wonderful, packaged, self-contained distribution of apache, mysql, php and tons of hard-to-install php extensions. Not only does it make sysadmin's life easier, by solving 99.9% of LAMP problems out-of-the-box, but it also allows PHP-vendors to create packaged distributions of complex systems.

However, even with a long list of packaged extensions, obviously there may be a need to install an additional one. PECL Memcache client of memcached distributed cache server, is a very probable candidate for high-load systems.

Unfortunately, PECL is broken in a vanilla XAMPP installation with php4. Typically you won't be able to use "pecl" directly and when you try to install manually with phpize you will get an error like:
" PHP Warning: Unknown(): Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20020429/memcache.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20020429/memcache.so: undefined symbol: OnUpdateLong in Unknown on line 0"

HOWTO: Enable PEAR on OS-X XAMPP

The current, OS-X version of XAMPP comes with PEAR but it's not installed/configured.

Here is what you need to do:

sudo su -  [and type admin password]
/Applications/xampp/xamppfiles/lib/php/pear install PEAR
/Applications/xampp/xamppfiles/lib/php/pear install Log
/Applications/xampp/xamppfiles/lib/php/pear list 

The last command outputs the list of installed pear modules. Log should be one of them.

Once you configure pear and install Log plugin, you need to add PEAR to include_path in XAMPP's php.ini.

Edit /Applications/xampp/etc/php.ini and at the very end of the file note the lines:

1133 ;***** Added by go-pear
1134 include_path=".:/Applications/xampp/xamppfiles/lib/php"
1135 ;*****

change the configuration to read:

include_path = ".:/Applications/xampp/xamppfiles/lib/php
                 :/Applications/xampp/xamppfiles/lib/php/pear"

(comment: of course, the entire include_path must be on the same line, we had to break it at semicolon to avoid the long line destroying the page layout).

Syndicate content