Archive for February, 2010

Published by Rolf on 10 Feb 2010

Making Windows 7 Search a little less dysfunctional

I was never a fan of Windows Desktop Search.  I had stuck with Google Desktop Search for a long time, but gradually got sick of the CPU hogging and so gave Windows Search (on Vista) another try.  It seemed to find emails in Outlook well enough, but as a tool for file-searching, it frankly sucked.  It just wouldn’t find stuff I knew was there.  So I was forced to go low-tech to, say, find all files with the word “wordpress blog” in them:  either

  1. Use the “Find In Files” feature of Visual Studio
  2. Fire up a Cygwin bash shell and use the trusty old grep.

I was rather disappointed to find the same shortcoming in Windows 7 Search: that it would completely fail to find plaintext files that contained some string.  How much simpler a request can you make?

Turns out Windows 7 can do what I am looking for, it just needs to be reconfigured in two significant ways:

  1. In the Start search box type in “Indexing Options” to open that control panel.
  2. Click the Advanced button.
  3. Make sure that the file extensions you hope to find are set up to “index file contents”, which isn’t the default behavior.  So go to the “File Types” tab and find the extensions you’d like to find (in my case it was “php”).  Highlight it and then click the “Index Properties and File Contents” radio button.  If you can’t find the file type you’re looking for, you’ll have to add it at the bottom.  Repeat for other file types.
  4. OK out of the “Advanced Options” dialog.
  5. Then, despite what the Windows 7 documentation says, simply adding a directory to a Library does not make it get indexed.  So click the “Modify” button and manually add whatever directory you want indexed.
  6. You probably want to delete and rebuild the index at this point (in the Advanced Options) dialog, then go for a nice long walk as it could take hours to finish the indexing.

Do all this, and finally Windows 7 Search will at least work.  Now it’s still not quite as fully-functioned as, say,Visual Studio Search, for the following reasons:

  1. I don’t get preview snippets of PHP (or Javascript, or CSS, etc.) files in the search results, although I do for HTML files.  Huh?  Both are plain text, and Windows 7 knows that!
  2. Non-alphanumeric characters get totally ignored in the search term.  E.g., I’m a big fan of FirePHP, but good luck doing a search for all instances of, say, “fb(“.  The parenthesis gets dropped.

Enjoy.

Published by Rolf on 05 Feb 2010

Installing APC on PHP 5.3

In a previous post I had some instructions for building PHP 5.3 on 64-bit CentOS 5.  Turns out the caching extension listed there, eAccelerator, didn’t show a marked performance benefit in our benchmark testing.  So instead I decided to play with APC, one of the competitors.  Getting this installed was a bit tricky though (e.g., compiling statically errors out), so follow these steps:

# First build PHP as usual, since we'll be installing this as a shared extension
# Then try to get rid of any leftover header files
yum remove php-devel
 
# Symlink your "real" php include directory
mv  /usr/local/include/php /usr/local/include/php-previous-version
cd /usr/local/include
ln –s /path/to/new/php/source/dir php
 
# only the beta version of APC works on PHP 5.3; see http://pecl.php.net/bugs/bug.php?id=16078
pecl install apc-beta
mv /usr/local/lib/php/extensions/no-debug-non-zts-20060613/apc.so /usr/lib/php/modules
 
# copy the APC dashboard script to your webroot
cp /usr/local/lib/php/apc.php /path/to/your/webroot
 
# Add the extension in a new file /etc/php.d/apc.ini
; Enable apc extension module
extension=apc.so
apc.enable = 1

Bounce apache and then go to yourdomain.com/apc.php to see the status.

Enjoy.

Published by Rolf on 05 Feb 2010

Warnings when upgrading a CakePHP application to PHP 5.3

If you’re moving to PHP 5.3, you’ll find that CakePHP throws a lot of “Deprecated” warnings.  Since Cake sets error_reporting to E_ALL, you’ll have to edit the core.  Change cake/libs/configure.php as follows:

error_reporting(E_ALL);

to

error_reporting(E_ALL ^ E_DEPRECATED);

That should do it.

Published by Rolf on 02 Feb 2010

Controlling the PHP error level in a WAMP virtual host

I usually set error_reporting to E_ALL when developing (forces you into good coding habits). When upgrading to PHP 5.3, a lot of “Deprecated” messages started showing up in some external software, though (things like CakePHP, WordPress, and Joomla).  Since I’m not about to touch that stuff, it’s far easier to simply lower the error reporting level in the short run.

Using the php_admin_flag, this is easy, once you translate the PHP constants into integers.  In the virtual host configuration (located in conf/extras/httpd-vhosts.conf in the latest version of WampServer), just add something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
 
Listen XX
<VirtualHost *:XX>
DocumentRoot "C:/path/to/root"
<Directory />
 ...
 
 <IfModule mod_php5.c>
 php_admin_flag engine on
 
 # choose the one you want:
 
 # This is for E_ALL & ~E_STRICT & ~E_DEPRECATED
 # php_admin_value error_reporting 22527   
 
 # This is for E_ERROR
 # php_admin_value error_reporting 1   
 
 </IfModule>
 
</Directory>
</VirtualHost>
 
...

Enjoy.