Drupal Development Tools

Call to undefined function cache_get()

When debugging with Zend Studio, you may get the fatal error "Call to undefined function cache_get()" when debugging, even though your site appears just fine in the browser.

Zend Studio seems to search open files first without regard to their actual paths. In my case, I had the cache.inc file from the views module open in Zend, and Zend was loading that instead of includes/cache.inc during debugging. Simply closing the file solved the problem.

Zend Platform on an Intel Mac

Finally. After over a year, Zend has recompiled their debugging extension so it will run on Intel Macs. That's the good news. The bad news is that now it's part of their enterprise-class Zend Platform product.

I'm running the 30-day trial, and was able to install it by running the install shell script and choosing the manual option to enter my Apache settings. Apache wouldn't restart after the installation because of course the xdebug extension that I had enabled in my php.ini file needed to be disabled.

Searching Drupal code

Often I find myself in the position of having to find something in the Drupal codebase. It's easy to do; from the command line:

cd drupal5
grep -rn contact .

This recursively searches the code for Drupal 5 and returns all occurrences of the word "contact", along with the filename and line number. Suppose I'm searching for the places where the contact database table is updated in Drupal. I can pipe the results into another grep:

grep -rn contact . | grep UPDATE
./modules/contact/contact.module:227:    db_query('UPDATE {contact} SET selected = 0');
./modules/contact/contact.module:242:    db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);

If you find yourself doing this frequently, it's helpful to make a shell script. I use OS X, and in my user directory I have created a directory called bin in which my scripts live. Of course, I've had to modify my /Users/john/.profile file to include that path when OS X is searching for executables by adding the following line:


I created a file at /Users/john/bin/f that contains the following line of code:

grep -rn $1 .

Now instead of typing grep -rn contact . I can simply type

f contact

Quick 'n' easy. For more shortcuts, see Steven's handy tips.

Zend Studio 5.5 debugging on OS X via Ubuntu and Parallels

Here's how to get debugging working in Zend Studio Server 5.5 for the Mac. There is no native version of Zend Platform for OS X on Intel Macs yet, so this solution uses Ubuntu on Parallels as an interim solution.

Installing Ubuntu on Parallels

I downloaded Ubuntu 6.10.
In Parallels, new virtual machine, typical installation.
Guest OS Type: Linux.
Guest OS Version: Debian Linux.
Called the Virtual Machine "Ubuntu".
Uncheck "Start guest OS installation".
Clicked on CD/DVD-ROM and changed the Emulation from Use CD/DVD-ROM to Use image file.
Pointed the image file to ubuntu-6.10-desktop-i386.iso
Blicked on Options, then Booting Options.
Changed Boot sequence to have CD-ROM boot first.
Started virtual machine which booted off the image file.
Pressed enter to boot from LiveCD.
Selected U.S. English.
Selected "Erase entire disk".
After installation, selected "Continue using LiveCD"
Powered off virtual machine.
Changed boot sequence to have hard disk boot first.
Booted and logged in.
System - Preferences - Screensaver Preferences, uncheck Activate screensaver.
Tested network connection.

Installing Apache, PHP, and Samba

You can use either the command line or Synaptic Package Manager to install software. If you use Synaptic:
System - Administration - Synaptic Package Manager
Settings - Repositories, check Community maintained Open Source software

I used the command line:

sudo bash
apt-get update
apt-get install apache2-mpm-prefork apache2 libapache2-mod-php5 php5-mysql smbfs

Mounting OS X Filesystem on Ubuntu

Now Apache and PHP are installed. Next, I wanted to mount my OS X filesystem on Ubuntu.

Started Windows File Sharing on OS X.

Firewall, chose New... and selected SMB (without netbios) (445 TCP).

Made the following addition to /etc/smb.conf on OS X (xxx.xxx.xxx.xxx is the IP of the Ubuntu virtual machine).

; allow connections only from the VM
hosts allow = xxx.xxx.xxx.xxx

; verbose logging in /var/log/samba/log.smbd
log level = 3 passdb:5 auth:10 winbind:2

; share my Sites folder
  path = /Users/john/Sites
  read only = no
  browseable = no
  comment = Websites

And I commented out the [homes] section because I'm paranoid.

Now I went to Ubuntu's terminal to mount the share:

mkdir /home/john/sites
mount -t smbfs //my.mac.ip.address/sites /home/john/sites -o username=myosxusername

I tested and doing ls gave me a list of the files in /Users/john/Sites. OK so far.

Serving my Sites directory via Ubuntu

Now I want Apache to serve out of /home/john/sites instead of the default /var/www. (I have no other use for Apache on this VM, so I'm editing the default settings.) So in Ubuntu I said

nano /etc/apache2/sites-enabled/000-default

When I was done it looked like this:

<VirtualHost *>
	ServerAdmin my@email.address
	DocumentRoot /home/john/sites
	<Directory /home/john/sites
	  Options Indexes FollowSymLinks MultiViews
	  AllowOverride All
	  Order deny,allow
	  deny from all
	  allow from
	  allow from my.mac.ip.address

I restarted Apache with apache2ctl restart.

I made a little file called test.php with just <?php phpinfo(); ?> in it. Going to http://xxx.xxx.xxx.xxx/test.php showed the PHP info page. So Apache and PHP are now running.

Installing Zend Platform on Ubuntu

Now it's time to install Zend Platform. I downloaded it from Zend and installed it on Ubuntu:

tar -xvf ZendPlatform-3.0.0Beta-linux-glibc21-i386.tar.gz
cd ZendPlatform-3.0.0Beta-linux-glibc21-i386/
bash ./install

Note that you need to type bash ./install instead of ./install because /bin/bash is really /bin/dash on Ubuntu.

I accepted all the defaults except on the WEB SERVER SETTINGS page, where I entered /home/john/sites in the htdocs field.

I did the Express option. It took several minutes and then completed.

On Ubuntu I started Firefox and went to http://localhost/ZendPlatform and logged in. Only localhost is allowed to do debugging and profiling sessions by default, and I wanted to do that from my Mac (that's sort of the whole point of this exercise!). So I clicked on Configuration and added my host to Allowed Hosts.

Configuring Zend Studio 5.5

Now I needed to configure Zend Studio 5.5 on my Mac to use Ubuntu. In Zend Studio, I added the IP of the Ubuntu virtual machine to Tools - Preferences - debug.

One final step: the debugger on Ubuntu connects back to Zend Studio on the Mac via port 10000. So I opened that port on my firewall.

To test, I chose Tools - Test Debug Server Connection and it reported success.


I now have a single filesystem that I can access via normal HTTP by issuing a request to my Mac, or via debugging by using Zend Studio to issue a debugging request via Ubuntu.

Drupal ninjas will notice that I haven't installed MySQL on Ubuntu. That's because I'll configure the site-specific Drupal settings file to point to the MySQL on my Mac. One database. One filesystem. Two Apache/PHP installs. Sweet.

Note: after trying this for a bit, it seems that Zend Platform's "Dynamic Content Caching" causes Apache/2.0.55 PHP/5.1.6 to segfault. Turning it off in the Zend Platform control panel at Performance - Settings -Dynamic Content Caching made the problem go away.

Update: after more investigation, it turns out that the segfaulting is due to the Zend Optimizer. Commenting out the following line in /usr/local/Zend/Platform/etc/php.ini eliminates the segfaults:



Subscribe to RSS - Drupal Development Tools