Spiga

Speeding your php application by tweaking the php configuration

by Gabi Solomon

This article is meant to help you to speed up your application by by tweaking the php configuration. The time gained might not be to visible to the user, but i should relief a little of the load on the server. Also this tweaks are going to help you a little in security.

If you are on a shared server and dont know how to change your php configuration you might want to check this article also.

But enough talk and lets get right into it. I will write the configuration name, the recommended setting and how this helps your application.

short_open_tag = Off

This will turn off short tags ( <? …. ?> ) and have the php engine one problem less to worry about.

asp_tags = Off

Do not use ASP like tags: <% echo “hello world”; %>

memory_limit = 32M

This is one configuration that you might need to tweak once in a while. But for start it is better to set it to a lower value and adjusting it when you need it. This will help you keep track of your aplication memory usage.
An article about memory usage you can find here.

register_long_array = Off

This will tells PHP to not register the deprecated long $HTTP_*_VARS type predefined variables. The default value is On. Since almost nobody ever uses them any more ( unless they have some compatibilty problems with old scripts, and they need them on ) it’s recommended to turn them off, for performance reasons. Instead, use the superglobal arrays, like $_GET.

This directive became available in PHP 5.0.0 and was dropped in PHP 6.0.0.

register_argc_argv = Off

This is more or less the same with register_long_arrays referring mostly to GET informations so it should be set to Off as well.

auto_globals_jit = On

This makes php stop generating the SERVER and ENV variables at script start ( default behaver ) and generating them when needed (Just In Time). These should help performance by cutting down the memory used by your scripts.
For this to work you need to have register_globals, register_long_arrays, and register_argc_argv disabled.
As an inside info : i tried this on a server .. .and it didn’t seem to create any SERVER or ENV variables, but i guess it was the server configuration because on a different server it worked :D .

magic_quotes_gpc

From my experience having this on can be a real pain in the [****]. When this is on, all ‘ (single-quote), ” (double quote), \ (backslash) and NUL’s are escaped with a backslash automatically. Why this is bad ? because you dont have a control over it. For example you use a mysql wrapper for youre database interactions that already has an escape function, this will make your values double escaped, and you endup after a few submits with a bunch of backslashes. So better have it off and do your own escaping, and maybe use a cleaning function to prevent SQL Injection ( more info here )

always_populate_raw_post_data = Off

Raw Post data is one of the more advanced knowledge, so if you dont use it, relief php of it concern :D and set always_populate_raw_post_data = Off.

Related Posts