256 Kilobytes

Answers in Frameworks | By August R. Garcia

Published 2 months agoTue, 12 Mar 2019 03:30:21 -0700 | Last update 2 months agoTue, 12 Mar 2019 04:53:04 -0700

68 views, 0 RAMs, and 0 comments

Tags: Laravel, Databases, Debugging, Ghetto Hacks

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 136 🗨 713 🐏 166
Site Owner

Step 1: Open app/Providers/AppServiceProvider.php

Step 2: Add this code to the boot() function:

        if ( TRUE ) {
                $GLOBALS['num_queries'] = 0;
                \DB::listen(function ($query) {
                        ob_start();
                        var_dump([
                            $query->sql,
                            $query->bindings,
                            $query->time
                        ]);
                        $result = ob_get_clean();

                        // Execution time in milliseconds       
                        $time = $query->time;

                        if ($time > 3)       $color = "background-color:red;"   ;
                        elseif ($time > 1)   $color = "background-color:orange;";
                        else                 $color = "background-color:yellow;";

                        // Display boxes in the body of the HTML document with query info
                        echo "<abbr style='color:black;$color font-weight:bold;padding:0.25em;border:1px solid black;margin:0.25em;' "
                             ."title=\"".htmlspecialchars($result)."\">float($time)</abbr>";

                        // Count the number of queries in the console
                        echo "<script>console.log('" . ++$GLOBALS['num_queries'] . "')</script>";
                });
                //echo "<h1>" . $GLOBALS['num_queries'] . "</h1>";     
        }

Change the if (TRUE) to FALSE or some other condition to disable the output. Possibly use if ( env('APP_ENV') == "local" ) to automatically disable on production.

Download more RAM. 🐏 ⨉ 0 Posted by August R. Garcia 2 months ago

Edit History

• [2019-03-12 3:30 PDT] August R. Garcia (2 months ago)
🕓 Posted at 12 March, 2019 03:30 AM PDT

The CIA wants all code in the cloud under their lock and key. They want to ban compilers and make people think HTML is computer programming. - Terry A. Davis

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.