User login

php

Use echo instead of print in themes for speed?

Hat tip to RobLoach who noted this in the #drupal IRC channel-- if we want to squeeze hundredths of a millisecond more out of our Drupal modules and themes, we should use echo instead of print for getting the data to the screen.

UPDATE: The PHP developers don't recommend switching from print to echo for speed reasons, suggesting that the difference can be dependent on the setup of your environment.

Random more useful PHP code speed improvements:

Install and enable pspell for Apache with PHP5

This is a package requested by, at the least, the Coder Tough Love Drupal module.

Searched around for a fix to the error message on the coder tough love settings page that there was nothing to configure because it didn't have the pspell package installed, nothing at results for ubuntu pspell, enable pspell, php5-pspell, enable pspell linux said exactly what to do.

Naturally...

sudo apt-get install php5-pspell
sudo /etc/init.d/apache2 restart

is all you need on Debian / Ubuntu.

Convert an associative array to variables with the names of the keys and the matching values

php turn an array into variables matching keys
php associative array to variables

The function you want is

<?php
 extract($array);
?>

http://us.php.net/extract

You can also do it the hard way.

PHP function to format seconds as hours:minutes:seconds

Could not find a built-in PHP function to convert seconds to minutes and such, so here's a utility function candidate. Seems it should be easier...

Syndicate content