add_*_vars() speed-up

php.internals

Andrei Zmievski

20 years ago
Based on Rasmus's profiling efforts, we have determined that add_cgi_vars() and add_common_vars() are taking a lot of time. Having taken a look at their implementation it seems that they are doing some unnecessary stuff, like creating a temporary table, filling it with entries and then calling ap_overlap_tables() which is supposed to overlap it over r->subprocess_env. But r->subprocess_env contains only a couple of entries by the time add_common_vars() is called, so it would be faster to add entries to it directly. Also, add_cgi_vars() was doing a subrequest in case r->path_info was present, which is completely unneeded for PHP as Apache module. The solution is to duplicate the functionality of these functions in mod_php5.c which is what the attached patch does. It also sets PATH_TRANSLATED in r->subprocess_env directly, so sapi_apache_register_server_variables() does not need to special case it. Please look it over and test. It seems to give about 7% boost on average. -Andrei

Dmitry Stogov

20 years ago
Hi Andrei, I don't see AUTH_USER, HTTPS..., CLIENT_CERT, HTTP_HOST, REQUEST_LINE, SERVER_URL. May be not all of them necessary and available in apache, but AUTH_USER, HTTPS are required for PHP. Thanks. Dmitry.

Rasmus Lerdorf

20 years ago
Those are all generated elsewhere. Have a look at: http://lerdorf.com/info.php This server is running the patch and as you can see HTTP_HOST is there, for example. -Rasmus Dmitry Stogov wrote:

Andrei Zmievski

20 years ago
Dmitry, My patch is almost exactly the same code as the original add_common_vars() and add_cgi_vars() functions except that it avoids the expensive ap_overlap_tables() call and replaces some ap_table_setn () calls with ap_table_addn(). -Andrei On Mar 16, 2006, at 11:25 PM, Dmitry Stogov wrote:

Andrei Zmievski

20 years ago
This is the updated patch. * Remove check for SECURITY_HOLE_PASS_AUTHORIZATION, since we are not CGI and can always skip these headers. * The optimization is only done for main request now. We check for r->main (sub-request) and r->prev (internal redirect, like on ErrorDocument). If either one of those is set, we call Apache functions to populate the subprocess environment. -Andrei

Dmitry Stogov

20 years ago
Hi Andrey, But original code probably know nothing about SSL. Will you patch work with Apache-SSL and Apache-EAPI/mod_ssl? Will it set HTTPS... variables? May be I missed, by I didn't see where you patch set AUTH_USER. But it is not hatrd to check this. :) Thanks. Dmitry.