New SPL Features in PHP 5.3 Webcast Slides
Hope you were able to make it to the CodeWorks 2009 webcast at which I presented on New SPL Features in PHP 5.3! I've posted the slides and source code. I hope you enjoyed the webcast and that you'll register for the excellent selection of upcoming webcasts leading up to CodeWorks 2009.
php|tek 2009 Slides
If you made it out to php|tek and saw my uncon session on web scraping, the slides have been posted. If you'd like to discuss the topic further, feel free to contact me. I love chatting about the subject with others.
Lethargy
I don't generally use this blog to write about personal matters. However, I feel the need to clear the air a bit about something that's been weighing on me lately. If you're reading this, chances are that I'd like you're advice about how to deal with this situation I'm in.
Those who know me are aware that I'd been working on a book up until recently. The manuscript for that book is now in the hands of my publisher's editor. At this point, there's nothing for me to do but sit back and wait for it to be reviewed so any residual editing can be done before the book goes to print.
I worked toward this state of completion for many months. It sapped nights, weekends, and other moments that might otherwise have been free. The feeling of it being completed, at least until editing starts, was understandably a relief of sorts. What followed, though, wasn't something I'd expected.
I thought that, after a period, I would reconstitute myself and get back into the ring, so to speak. Whatever the next project was, be it working on Phergie or Zend Framework, I would start.
But I can't seem to find motivation. There's this ever-present feeling of lethargy where there used to be enthusiasm. I remember feeling similar to this when I graduated from college. As long as I had been waiting for time to work on other projects, my own projects, it felt like I didn't have it in me when the time finally became available.
I'm not sure that state ever went away or, if it did, how I got rid of it the last time. All I know now is that I'm not sure what to do about it. Maybe it's burn-out? I don't know. It's not a feeling I like, but I'm not sure how to rid myself of it. It's like an angst to do something, a restlessness, but nothing that comes to mind seems enticing.
Have you ever felt something like this? If so, how did you get past it?
Building PHP-GTK with Cairo Support on Ubuntu Jaunty
Elizabeth Smith
I'm assuming here that you want to use as many available Ubuntu packages as is feasible, aside from maybe PHP itself, in order to minimize the amount of manual compilation necessary. To that end, there are a number packages you will need to install before getting started that do not come with a standard Jaunty installation.
sudo apt-get install subversion cvs libcairo2-dev libgtk2.0-dev
If you plan to build PHP from source, you will also need a few more packages.
sudo apt-get install build-essential autoconf libxml2-dev
Once you've got all the dependencies installed, the first step will be to grab a copy of PHP. You've got a few options in that regard.
- Install the stock php5-cli and php5-dev packages available for Ubuntu.
- Download a copy of 5.2.9 or, if you want the new shiny stuff, 5.3.0RC1.
- Download a current snapshot of the 5.2 or 5.3 branches.
Assuming you do a custom build, here's how I did it.
./configure --with-gettext --disable-cgi --without-pear \
--prefix=`pwd`/build/php_build
make
make installNext, use Subversion to check out a copy of Cairo extension. If you did a custom PHP build, you can just place it on the same directory level as that.
svn co svn://whisky.macvicar.net/php-cairo cairo
At the present moment, the easiest way to install the Cairo extension is manually as a PECL extension. So, compile using the phpize utility in your PHP build.
cd cairo
../php-5.3.0RC1/build/php_build/bin/phpize
./configure --prefix=`pwd`/build/php_build \
--with-php-config=../php-5.3.0RC1/build/php_build/bin/php-configIt's at this point that Ubuntu's "interesting" automake package comes into play. The Makefile generated by phpize will be missing a critical flag -DCOMPILE_DL_CAIRO in its CFLAGS setting value. Open the Makefile in any text editor and find the line that looks like this.
CFLAGS = -g -O2
Append the missing flag to the line so it looks like this, then save it.
CFLAGS = -g -O2 -DCOMPILE_DL_CAIRO
At that point, just continue the compilation process for the Cairo extension as normal.
make make install
Now use CVS to check out a copy of the PHP-GTK extension. Place it on the same directory level as cairo.
export CVSROOT=:pserver:cvsread@cvs.php.net:/repository cvs -q checkout -P php-gtk
If the phpize utility is not in your PATH, you'll have to assign it to an environmental variable as those are the only two ways that the buildconf utility you're about to use will pick it up.
export PHPIZE=../php-5.3.0RC1/build/php_build/bin/phpize
Execute the buildconf utility to generate the configure script, then execute it.
./buildconf
./configure --prefix=`pwd`/build/php_build \
--with-php-config=../php-5.3.0RC1/build/php_build/bin/php-configTo have the PHP-GTK extension take advantage of the presence of the Cairo extension, you'll need to add a flag to the CFLAGS setting in its Makefile. Open that, find the line that looks exactly like the original one modified in the Cairo Makefile, and append the flag -DHAVE_CAIRO to it so it looks like this.
CFLAGS = -g -O2 -DHAVE_CAIRO
At that point, continue the compilation process normally just as with the Cairo extension. Once that's done, since the extensions were compiled as PECL extensions, you'll need to enable them in your php.ini file.
If you did a custom build of PHP, just copy the php.ini-development file in the root of the extracted tarball directory to lib/php.ini within your build directory as this is where PHP will look for it by default. If you're using PHP 5.3.0RC1, there is a syntax error around line 581 of that file. A URL should be commented out using a semicolon but isn't. Note that the extension_dir setting needs to be set and, if you use a relative path, it must be relative to the current working directory from which PHP is invoked (the root PHP build directory in my case).
extension_dir = "lib/php/extensions/no-debug-non-zts-20090115" extension=cairo.so extension=php_gtk2.so
At this point, if you execute your php binary with the -m switch, you should get a list of extensions loaded. cairo and php-gtk should be among them and you shouldn't see any errors before the extension listing. To take this for a test spin, there's a particular demo file for PHP-GTK with Cairo support in the php-gtk checkout.
cd php-5.3.0RC1/build/php_build bin/php php-gtk/demos/examples/cairo_support.php
If this works as expected, you should see a nifty little PHP-powered clock widget on your desktop.

Many thanks to Elizabeth for her help in putting this tutorial together and for all the very cool people working on the PHP-GTK project. You can find them in the #php-gtk channel on the Freenode IRC network. At the present time, some of them are in the process of revamping the PHP-GTK docs. In the meantime, you can check out the GTK docs for more current information.
CDC Update
While using cdc recently after having written about it, I ran into an odd issue. While doing a lint check on a code block, a parse error was occurring on a line that contained a comment in the original source file.
The original code block to do this lint check had the line below to do the heavy lifting.
$response = shell_exec('echo ' . escapeshellarg($code) . ' | php -l');A var_dump() on $code revealed this, where the comment line was the line on which the parse error was occurring.
string(474) "<?php
...
// Matches any of the standard escape sequences \r, \n, or \t
$matches = (preg_match('/\\r|\\n|\\t/', $string) == 1);
...
?>"Presumably what was happening was, even though the var_dump() call showed that actual newlines were being interpreted correctly, the \r was also being interpreted rather than taken literally. This caused the comma following it to generate the error I was receiving, namely "Parse error: syntax error, unexpected ','." (If you know why this is, I'm very curious to find out.)
Luckily I was able to tag Derick and he pointed me in the direction of an alternative: proc_open, which even has an example for executing a PHP file that works just as well when modified to perform a lint check on a PHP file. You can see the code changes in the related git commit.
