Friday, 5 August 2011

Tech tip #1 : using .htaccess instead of php.ini

I've decided to put a few notes here that related to my new (at the time of writing) job.
I find that you normally learn all kinds of useful stuff when you start a new job, but I often forget to document it.

If I'm lucky I'll remember to bookmark the place where I discovered my new knowledge so I can find it again, or if not I'll have to google it and hope that the same links come up.

This time I've decided to add a few posts here.

So - yesterday I needed to increase the memory limit and maximum execution time for a particular php script after getting a support email from a user. Updating the code with ini_set() or set_time_limit() wasn't an option, as they try to keep code modifications to a minimum here, to ease future upgrades.

Normally I'd head over to edit the php.ini file to edit memory_limit and max_execution_time and reload or restart apache, but in this new job I'm very much a developer rather than a sysadmin. This means that I don't have access to config files, nor the permissions to mess about with the apache daemon.

So - I had to go down another route that was new to me : using .haccess.

It turns out it's really simple to do this, just add the desired values in the .htaccess file for these two values. After checking with the sysadmin that I wasn't going to break his server I was able to add :

php_value memory_limit 360M
php_value max_execution_time 180

Problem solved, user happy, back to real work.