Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any Laravel Profilers that work with JSON APIs? [closed]

Tags:

laravel

I've seen barryvdh's debugbar, but it seems to only work when you're serving pages. Every single response from my site is application/json.

Is there some hidden option I'm missing in barryvdh's bar or is there another option for Profiling my L4 app?

I'm not asking for ranking or opinions, just a link to any profiler that can just dump results to an Array or log file.

like image 809
CJ Thompson Avatar asked Nov 18 '14 16:11

CJ Thompson


2 Answers

So, I was frustrated with the solution I described earlier and went ahead and created a fork of laravel-debugbar that did exactly what I was looking for:

https://github.com/Dukeman330/laravel-debugbar

Basically I bolted on a "debugbar" route, controller, and view that opens a full-screen version of the debugbar, making it easy to walk through the debug files output by ajax queries. If you want to give this a shot, update your composer.json as follows:

"repositories": [{
        "type": "vcs",
        "url": "https://github.com/Dukeman330/laravel-debugbar.git"
}],
"require": {
    "barryvdh/laravel-debugbar": "dev-master"
},

Then, make your ajax calls as you normally would and to see the output, navigate to [your-site]/debugbar in a browser.


Previous Answer:

This isn't exactly an ideal solution, but I've been working around the same issue by setting up a little 'profiler' page that renders my JSON output with the profiler bar. I created a profiler.blade.php with the following:

<html>
  <body>
    <pre>{{json_encode($data, JSON_PRETTY_PRINT)}}</pre>
  </body>
</html>

Then, any time I want to profile a function I'm building, rather than return $output; I run something like:

return \View::make('profiler', ['data' => $output]);

Again, not ideal since the thing calling your rest API won't know how to handle this output, but it works pretty well if you're developing the API in a browser.

like image 161
Chris Garson Avatar answered Nov 10 '22 09:11

Chris Garson


You can Use

print_r($response);

instead of

return response()->json($response); //comment it

and open it in a browser (for get requests);

It's important you don't return anything

like image 4
Sebastien Horin Avatar answered Nov 10 '22 08:11

Sebastien Horin