filtering xdebug ini keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jemptymethod

    #1

    filtering xdebug ini keys

    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....Geor ge 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;
    }

  • jemptymethod

    #2
    Re: filtering xdebug ini keys

    On Oct 28, 8:53 am, jemptymethod <jemptymet...@g mail.comwrote:
    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....Geor ge 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;
    }

    Comment

    • Rik Wasmus

      #3
      Re: filtering xdebug ini keys

      On Sun, 28 Oct 2007 13:53:34 +0100, jemptymethod <jemptymethod@g mail.com
      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....Geor ge 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;
      }
      What you should be doing:

      $ini_xdebug = ini_get_all('xd ebug');

      To answer your question, something like (untested):

      <?php
      function _is_xdebug($str ing){
      return preg_match('/^xdebug/i',$string);
      }
      $all = ini_get_all();
      $keys = array_keys($all );
      $neededkeys = array_filter($k eys,'_is_xdebug ');
      $xdebug = array_intersect _key($all,array _flip($neededke ys));
      ?>
      --
      Rik Wasmus

      Comment

      • jemptymethod

        #4
        Re: filtering xdebug ini keys

        On Oct 28, 9:28 am, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
        >
        To answer your question, something like (untested):
        >
        <?php
        function _is_xdebug($str ing){
        return preg_match('/^xdebug/i',$string);}
        >
        $all = ini_get_all();
        $keys = array_keys($all );
        $neededkeys = array_filter($k eys,'_is_xdebug ');
        $xdebug = array_intersect _key($all,array _flip($neededke ys));
        ?>
        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($str ing, 'xdebug') didn't even
        save a 10th of a millisecond (0.016824 vs. 0.016918).


        Comment

        Working...