Jump to content

TracyDebugger when running scripts on the command line, possible?


Recommended Posts

Oftentimes I'll have little scripts that bootstrap ProcessWire and do various things.  These scripts usually echo out information.

However, I'm beginning to start using the Console feature of TracyDebugger as somewhat of a replacement.

One thing I'm wondering is if a snippet can work nicely whether I run it with the php command vs. the TracyDebugger console.

So for example, I have this in /site/templates/TracyDebugger/snippets/test.php:

<?php namespace ProcessWire;
if(!defined("PROCESSWIRE")) include(dirname(__FILE__).'/../../../../index.php');

d($pages->get(1));

If I run that in TracyDebugger Console, it outputs nicely due to the d() function.

However if I run it with php directly like this:

php site/templates/TracyDebugger/snippets/test.php

... it won't output anything.  I'm guessing this is because (a) TracyDebugger doesn't run in CLI mode and (b) TracyDebugger is disabled in this state given my settings and (c) the d() function doesn't run in CLI mode.

Is there some slick way to do this, or some alternative best practice?

Link to comment
Share on other sites

If I enable guest dumps (via the button on the panel selector) and use bd() instead of d() then after calling a script via the command line, I can reload the site in the browser and the bd() calls will be displayed. Does that help?

The only other solution I can think of at the moment is to maybe check if the snippet is called via the CLI and convert d() calls to print_r() automatically? I've done some quick experiments on that idea and seems fairly useful.

image.thumb.png.5d65c4abeb61562e7dfbd083b793658e.png

 

By the way - just making sure that you're familiar with the Console panel's "Code Prefix" settings field for adding that:

<?php namespace ProcessWire;
if(!defined("PROCESSWIRE")) include(dirname(__FILE__).'/../../../../index.php');

block automatically to each snippet.

 

  • Like 1
Link to comment
Share on other sites

What I always do is to write those scripts in an object oriented way right from the beginning. That's as easy as adding one method to the Site.module.php

Then I add $site->doSomething() to ready.php and RockFrontend will live reload the page as soon as I update Site.module.php and I'll see all the dumps in Tracy. No need to switch screens. No need to switch windows. No need to use the mouse. Just write code, save, see the dumps.

And once everything works, everything is just an api call away! And, of course, it's under GIT. $site->party() 😉 

PS: And if you happen to need that for a cron or similar:

<?php
include "index.php";
$site->party();

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...