Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Php quick profiler bug?
  • Hello!

    I just to ask question about profiler.
    I have turned it on, but it do not shows sql queries.
    EXAMPLE:

    $sql = ''SELECT MAN FROM user';

    DB::query($sql)->execute()->as_array();
    What happens?

    image
  • Database profiling needs to be enabled seperately since it's quite performance impacting.

    You enable it on a per-connection basis, in your db.php (profiling => true).
  • I have enabled it, but it do not works.
    It is not a problem, just interesting bug.
    At one my friend - same problem.
  • I'm pretty sure it's not a bug, otherwise it would have been reported earlier, there hasn't been a code change in the profiler for many months.

    I can not reproduce it, as soon as I enable profiling in config.php and in the db.php 'default' definition I get the SQL info.

    As you sure you configured it correctly?
  • Yes, I am sure.


    db.php

    return array(
        'active' => 'default',

        'default' => array(
            'type'        => 'pdo',
            'connection'  => array(
                'persistent' => false,
            ),
            'identifier'   => '`',
            'table_prefix' => '',
            'charset'      => 'utf8',
            'enable_cache' => true,
            'profiling'    => true,
        ),

        'redis' => array(
            'default' => array(
                'hostname'  => '127.0.0.1',
                'port'      => 6379,
            )
        ),

    );


    config.php

    'profiling'  => true,
  • And what does your environment db.php looks like?

    Because this one doesn't contain any database definitions. No change that that will overwrite the setting?
  • I have remade.

    [development] Db.php

    return array(
        'default' => array(
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;dbname=my_dbname',
                'username'   => 'root',
                'password'   => 'password',
                       
            ),
                'profiling'    => true,
        ),
    );

    [config] db.php

    return array(
        'active' => 'default',

        /**
         * Base config, just need to set the DSN, username and password in env. config.
         */
        'default' => array(
            'type'        => 'pdo',
            'connection'  => array(
                'persistent' => false,
            ),
            'identifier'   => '`',
            'table_prefix' => '',
            'charset'      => 'utf8',
            'enable_cache' => true,
            'profiling'    => true,
        ),

        'redis' => array(
            'default' => array(
                'hostname'  => '127.0.0.1',
                'port'      => 6379,
            )
        ),

    );


  • Just a second, I'm stupid.

    I just noticed the problem is not that the profiler doesn't see the queries. It does, as it as says "2 queries" in the tab. The problem is that these two queries are not displayed.

    Just created a new 1.4 install, defined a DB connection using your config, and created a controller with a few ORM queries. Works fine, and the queries are displayed in the profiler.

    So I'm not sure what your problem is...
  • I am never using ORM. Just "raw" SQL language.
    Maybe my problem in it?

    I'll  try to run ORM.
  • The interface is between the query builder (DB classes) and the Profiler, so it doesn't matter what you use, DB calls, Model_Crud or DB should all log their queries.

    Just tried some DB and DBUtil calls in the same 1.4 test install, and they show up in the profiler without problems.
  • I found why profiler do not works.
    I am using Controller_Template.

    under Controller - works fine and shows sql queries.
    But under Controller_Template - nothing.
    And how to solve it?
  • There must be more going on.

    I just created a new installation of 1.5/develop, changed the welcome controller to use Controller_Template, added a database config, enabled the profiler, and added a DB query to action_index.

    Profiler pops up in the lower-right corner, and if I open it I see my 1 query. No problem.
  • Harro, please try to make that.
    [routes.php]
    '_root_'  => 'main/index',

    [Common.php]
    class Controller_Common extends Controller_Template {
    public $lang = null;
    public function before() {
            parent::before();
    $this->lang = 'en';
    }
    }

    [Main.php]
    class Controller_Main extends Controller_Common{
    public function action_index(){
    DB::query('SELECT * FROM man'. $this->lang)->execute()->as_array();
    }
    }


    My Main controller extends two other Controllers.

    Probably profiler do not correctly works with many "extending".

    I tried to run it under 1.4 and it falls.
    Profiler works but do not shows all information.
  • Just did exactly that on 1.5/develop, works without problems, query shows up in the profiler.
  • Tried a 1.4 installation too. Same result. Tried using both the PDO and the MySQLi drivers. Same result.
  • As to your earlier remark: queries are directly reported to the profiler from the DB connection drivers, where the DB originated is not relevant.
  • Very strangely, why at you everything - ok.
    But at me and my friend - profiler do not shows sql queries.

    If I will use profiler in standard Controller, profiler will shows sql queries.
  • Is is possible to zip your entire docroot (so including assets and fuel core), and post it somewhere (you can let me know via PM (inbox in the menu) if you don't want it public).

    Then I can see if I can reproduce it here, and if so, if I can find the cause.
  • Okay. Tomorrow I'll try to send you my code.

    I have made my little investigation.
    I fount problem.

    if I comment it: $response = $this->template; or it $this->template = \View::forge($this->template);

    Profiling works perfectly.
    Sure other (PHP) errors shows up.

    abstract class Controller_Template extends \Controller
    {

        /**
        * @var string page template
        */
        public $template = 'template';

        /**
         * Load the template and create the $this->template object
         */
        public function before()
        {
            if ( ! empty($this->template) and is_string($this->template))
            {
                // Load the template
                $this->template = \View::forge($this->template);
            }

            return parent::before();
        }

        /**
         * After controller method has run output the template
         *
         * @param  Response  $response
         */
        public function after($response)
        {
            // If nothing was returned default to the template
            if (empty($response))
            {
                $response = $this->template;
            }

            return parent::after($response);
        }

    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion