Jump to content

Issue when using Tracy with Laravel Valet


a-ok
 Share

Recommended Posts

I was using MAMP for local development for years and Tracy never had any issues.

I've recently just switched to using Laravel Valet with the custom driver and all seems okay but when I enable Tracy I get the following error.

When I disable Tracey and debug `$_SERVER['REQUEST_URI']` it returns false.

Any thoughts on how I can continue to use Tracy (which is so brilliant useful) when using Laravel Valet?

Thanks!

Screenshot 2021-02-08 at 13.55.58.jpg

Link to comment
Share on other sites

  • 1 year later...

I also have issues with tracy since I switched to laravel valet for my local development (Mac OSX Monterey). The panel is loading but I can not see field and template infos in the request info panel. Also I get an error when visiting a template settings page in the admin. The module works fine with the same setup (Site Export) on my shared hosting server. I access my site via http (http://projectname.test). Iam using Tracy version 4.23.25. Here is the template error:

ErrorException: Undefined variable: template in /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/panels/RequestInfoPanel.php:572
Stack trace:
#0 /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/panels/RequestInfoPanel.php(572): Tracy\Bar->Tracy\{closure}(8, 'Undefined varia...', '/Users/jploch/S...', 572, Array)
#1 /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-2.9.x/src/Tracy/Bar/Bar.php(141): RequestInfoPanel->getPanel()
#2 /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-2.9.x/src/Tracy/Bar/Bar.php(113): Tracy\Bar->renderPanels('')
#3 /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-2.9.x/src/Tracy/Bar/Bar.php(87): Tracy\Bar->renderPartial('main')
#4 /Users/jploch/Sites/PageGrid/dist/site/modules/TracyDebugger/tracy-2.9.x/src/Tracy/Debugger/DevelopmentStrategy.php(138): Tracy\Bar->render(Object(Tracy\DeferredContent))
#5 /Users/jploch/Sites/PageGrid/dist/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-2.9.x/src/Tracy/Debugger/Debugger.php(315): Tracy\DevelopmentStrategy->renderBar()
#6 [internal function]: Tracy\Debugger::shutdownHandler()
#7 {main}

I already tried this solution from the linked post above (changing the valet driver), with no success.

Link to comment
Share on other sites

Hi @jploch - I actually have a feeling this isn't Valet related. It looks like a bug in the RequestInfo panel. Any chance you have turned off some of the sections within it, likely the Template Settings section? It's an easy fix, but just wanted to confirm that you do have this disabled. It's probably that one second from the top that is causing the problem. You might have upgraded from a really old version of Tracy when that section didn't exist.

image.png.d3c1b06bd74a29699fd4adef7e10b95e.png

  • Like 1
Link to comment
Share on other sites

@adrian Thx! That was fast! The error is gone now. However I still don't see the field and template infos in the request info panel on my local installation.

Here is a screenshot of my local request info panel (Viewing the template settings page for template home)
1207900888_Bildschirmfoto2022-03-24um10_00_31.thumb.png.6924db3af9f2521404c3354abae9c8a0.png

And here is a screenshot from my shared hosting, both have the new tracy version installed (Viewing the template settings page for template home)1187078351_Bildschirmfoto2022-03-24um09_59_31.thumb.png.667435ee8105a79e418c60d9bf737ad7.png

Both have these settings for the info request panel:
1901627647_Bildschirmfoto2022-03-24um10_03_24.thumb.png.c288a82ecea176597e058e1626388eac.png

Link to comment
Share on other sites

Hi @jploch - it looks like the issue is a problem with what $_SERVER['PHP_SELF'] is returning. Could you please add the following code to line #53 of the RequestInfoPanel.php file and let me know what is returned?

bd($_SERVER['PHP_SELF'] . ' : ' . $this->wire('config')->urls->root . 'index.php');

 

  • Like 1
Link to comment
Share on other sites

6 minutes ago, adrian said:

Could you please add the following code to line #53 of the RequestInfoPanel.php file and let me know what is returned?

Thanks again for looking into this. Here is the dump return (local enviroment):

'/admin/setup/template/edit : /index.php'

 

Link to comment
Share on other sites

Interesting - Valet seems to mess with PHP_SELF. Could you please find out what 

bd($_SERVER['SCRIPT_NAME']);

returns.

It looks like there might be another option around setting: 'usePathInfo' => true in general.php (https://github.com/laravel/valet/issues/340) - is that something you are familiar with? I think general.php is a file in the Valet system, but not really sure.

  • Like 1
Link to comment
Share on other sites

5 minutes ago, adrian said:

Interesting - Valet seems to mess with PHP_SELF. Could you please find out what 

bd($_SERVER['SCRIPT_NAME']);

returns.

it returns:

'/index.php'

 

10 minutes ago, adrian said:

It looks like there might be another option around setting: 'usePathInfo' => true in general.php (https://github.com/laravel/valet/issues/340) - is that something you are familiar with? I think general.php is a file in the Valet system, but not really sure.

I don't have the file general.php on my system. Maybe it's a Craft CMS thing? Maybe I can update the ProcessWireValetDriver.php file, which I think is doing everithing to make valet and ProcessWire work together. Iam not very exoerienced with valet and php in general, so I have no idea where to start. I got the file from this thread (not sure which version I picked). Here is the code a have in that file, if it helps:
 

<?php class ProcessWireValetDriver extends BasicValetDriver {

    private $possibleDirectories = [
        '', // PW in root, do not remove except you're sure you never use it
        '/dist',
        '/public'
    ];

    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return bool
     */
    public function serves($sitePath, $siteName, $uri) {
        foreach ($this->possibleDirectories as $dir) {
            if(is_dir("{$sitePath}{$dir}/wire"))
                return true;
        }
        return false;
    }

    public function isStaticFile($sitePath, $siteName, $uri) {
        foreach ($this->possibleDirectories as $dir) {
            if(is_file($staticFilePath = "{$sitePath}{$dir}{$uri}"))
                return $staticFilePath;
        }
        return false;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string
     */
    public function frontControllerPath($sitePath, $siteName, $uri) {
        $_SERVER['SERVER_NAME']     = $_SERVER['HTTP_HOST'];
        $_SERVER['SCRIPT_NAME']     = '/index.php';
        $_GET['it']                 = $uri;

        if ($uri === '') {
            $uri = '/';
        }

        foreach ($this->possibleDirectories as $dir) {
            if(!file_exists($indexPath = "{$sitePath}{$dir}/index.php")) continue;

            // $_SERVER['REQUEST_URI'] = substr(str_replace($dir, '', $_SERVER['REQUEST_URI']), 10);
            $_SERVER['SCRIPT_FILENAME'] = $indexPath;


            if (file_exists($indexPath = "{$sitePath}{$dir}/install.php")) {
                return $indexPath;
            }

            return parent::frontControllerPath(
                "{$sitePath}{$dir}", $siteName, $uri
            );
        }
    }
}


 

Link to comment
Share on other sites

@jploch - thanks for those. I am honestly not sure the best approach to fix this. The problem in question is this:

// check if request is to a PW page - otherwise it's maybe an AJAX request to an external script
$isPwPage = $_SERVER['PHP_SELF'] == $this->wire('config')->urls->root . 'index.php' ? true : false;

But, I can't seem to trigger a situation at the moment where this returns false (even making an ajax request to an external script). I don't think I want to replace PHP_SELF with SCRIPT_NAME because I think that would return an incorrect result if the external script was an index.php file.

Possibly you could add:
 

$_SERVER['PHP_SELF']     = '/index.php';

to the frontControllerPath() method. I expect that will fix things, but not sure if there might be some side effects, but it might be the best solution. Let me know it that works for you.

  • Like 1
Link to comment
Share on other sites

@adrian I added that line to the function and restartet valet, but nothing changed as far as I can tell. I still don't see the field and template infos in the request info panel 

Link to comment
Share on other sites

1 hour ago, jploch said:

@adrian it still returns the same:

'/admin/setup/template/edit : /index.php'

 

Weird - I have no idea why that would be happening - maybe it can't be overwritten in Valet for some reason?

There might be a better way for me to check if the request is a response from PW page or not, but I am hesitant to change the current logic without understanding things a bit better.

Any Valet experts out there who have an idea on what the best way forward is?

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...