Archive for the ‘Web’ Category.

PHP: The include() include_once() performance debate

The include() include_once() performance debate

Updated with more tests on 2010-05-16.
Click here to jump to the 2010-05-16 update…

The conventional wisdom always said that PHP’s include()/require() was quicker than include_once()/require_once(), but recently I came across an interesting post by Arin Sarkissian which suggests otherwise. Also I found more commentary on the performance benefit of using relative versus absolute paths in include()/require() and include_once()/require_once() statements (although the main article’s conclusions contradict Arin’s experiments). The Drupal developers discussed and benchmarked the relative/absolute include() issue too.

So in keeping with the spirit of quick and dirty experimentation I hacked up some code and ran some tests on include()/require() against include_once()/require_once() and on the relative/absolute path issue. The results are pretty surprising and I love to hear some views.

Continue reading ‘PHP: The include() include_once() performance debate’ »

PHP Parse error: syntax error, unexpected T_STRING in /whatever/my-php-class.php.html on line 1 with PhpDocumentor files on CentOS

Apache LogoSymptom:

  • An XML file saved as something.php.html
  • Apache was trying to parse it as PHP and throwing an error because Short_open_tag was ‘on’

Fix:

Add the following to an .htaccess file in the folder (or a parent folder):

php_value short_open_tag off

I don’t know if this is a ‘bug’ or a ‘feature’. I don’t see why Apache should be interpreting *.php.html files as PHP (BAD Apache) but now that the issue is fixed for me I am not too concerned.

Update: 2010-05-07:

Kae Varens already came across this and blogged about it in October 2008. It turns out that

  1. it’s Apache – not me!
  2. there is a lot more to this than meets the eye

If you manage your own Apache web server then Kae’s blog post is required reading.

Using Apache mod_rewrite to redirect old URLs

Apache LogoThere are lots of examples and tutorials covering Apache and mod_rewrite, but generally they address the problem where you want to map a ‘nice’ url to your script. For example:

http://example.com/products/kitchen/cutlery

to

http://example.com/products.php?category=kitchen&sub-category=cutlery

is easily achieved with the following .htaccess rules:

RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/? /one.php?action=$1&category=$2&subcategory=$3 [L]

However if you want to rewrite in the other direction it might not be immediately obvious that you cannot use rewrite rules with your GET URL variables. So if you want to go from

http://example.com/products.php?category=kitchen&sub-category=cutlery

to

http://example.com/products/kitchen/cutlery

you need to sniff the query variables as well as the script name.
Continue reading ‘Using Apache mod_rewrite to redirect old URLs’ »