filtering xdebug ini keys
filtering xdebug ini keys
am 28.10.2007 13:53:34 von jemptymethod
I've created the following function for returning only ini keys that
pertain to xdebug. I'm wondering how I might go about doing the same
sort of thing with one or more of the various "array_" functions
instead (e.g. array_filter). Since I'm working with xdebug (if you
can't tell ;) I'll respond in kind with trace data comparing the
functions.
Thanks in advance....George Jempty
function ini_get_xdebug() {
$ini_all = ini_get_all();
$ini_xdebug = array();
$xdebug_prefix = 'xdebug.';
foreach ($ini_all as $k=>$v) {
if (substr($k, 0, strlen($xdebug_prefix)) == $xdebug_prefix) {
$ini_xdebug[substr($k, strlen($xdebug_prefix))] = $v;
}
}
return $ini_xdebug;
}
Re: filtering xdebug ini keys
am 28.10.2007 14:18:16 von jemptymethod
On Oct 28, 8:53 am, jemptymethod wrote:
> I've created the following function for returning only ini keys that
> pertain to xdebug. I'm wondering how I might go about doing the same
> sort of thing with one or more of the various "array_" functions
> instead (e.g. array_filter). Since I'm working with xdebug (if you
> can't tell ;) I'll respond in kind with trace data comparing the
> functions
Interesting trace data already....by moving the calls to
strlen($xdebug_prefix) outside the loop, I reduce execution time from
over 15 milliseconds to under 10
> Thanks in advance....George Jempty
>
> function ini_get_xdebug() {
> $ini_all = ini_get_all();
> $ini_xdebug = array();
> $xdebug_prefix = 'xdebug.';
>
> foreach ($ini_all as $k=>$v) {
> if (substr($k, 0, strlen($xdebug_prefix)) == $xdebug_prefix) {
> $ini_xdebug[substr($k, strlen($xdebug_prefix))] = $v;
> }
> }
> return $ini_xdebug;
> }
Re: filtering xdebug ini keys
am 28.10.2007 14:28:35 von luiheidsgoeroe
On Sun, 28 Oct 2007 13:53:34 +0100, jemptymethod
> =
wrote:
> I've created the following function for returning only ini keys that
> pertain to xdebug. I'm wondering how I might go about doing the same
> sort of thing with one or more of the various "array_" functions
> instead (e.g. array_filter). Since I'm working with xdebug (if you
> can't tell ;) I'll respond in kind with trace data comparing the
> functions.
>
> Thanks in advance....George Jempty
>
> function ini_get_xdebug() {
> $ini_all =3D ini_get_all();
> $ini_xdebug =3D array();
> $xdebug_prefix =3D 'xdebug.';
>
> foreach ($ini_all as $k=3D>$v) {
> if (substr($k, 0, strlen($xdebug_prefix)) == $xdebug_prefi=
x) {
> $ini_xdebug[substr($k, strlen($xdebug_prefix))] =3D $v;
> }
> }
> return $ini_xdebug;
> }
What you should be doing:
$ini_xdebug =3D ini_get_all('xdebug');
To answer your question, something like (untested):
function _is_xdebug($string){
return preg_match('/^xdebug/i',$string);
}
$all =3D ini_get_all();
$keys =3D array_keys($all);
$neededkeys =3D array_filter($keys,'_is_xdebug');
$xdebug =3D array_intersect_key($all,array_flip($neededkeys));
?>
-- =
Rik Wasmus
Re: filtering xdebug ini keys
am 28.10.2007 14:52:01 von jemptymethod
On Oct 28, 9:28 am, "Rik Wasmus" wrote:
>
> To answer your question, something like (untested):
>
>
> function _is_xdebug($string){
> return preg_match('/^xdebug/i',$string);}
>
> $all = ini_get_all();
> $keys = array_keys($all);
> $neededkeys = array_filter($keys,'_is_xdebug');
> $xdebug = array_intersect_key($all,array_flip($neededkeys));
> ?>
For "untested" that worked out of the box ;) Thanks very much for the
lesson on how to use these array_ functions.
My very first trace however indicates 17 milliseconds. And replacing
the regular expression with 0===strpos($string, 'xdebug') didn't even
save a 10th of a millisecond (0.016824 vs. 0.016918).