valet: Painfully slow response times in Valet + tons of 504 gateway timeouts

Problems:

  • Regular 504 time outs
  • upwards of 30 seconds per reload

The whole thing is crazy slow. I have no idea where to start on how to fix this.

What I’ve done: » reinstalled valet » changed memory_limit to = 256M » updated valet » updated brew » restarted valet » restarted machine » swore loudly

I’m running 7.1.25

Any help pointing me in the right direction would be awesome.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 42 (14 by maintainers)

Most upvoted comments

LOLOL var_rump i’m gonna call it a day

My solution isn’t an overly viable one, but yes I did solve it by buying a new iMac. 🙄

(the var_rump thing is a typo in Matt’s suggested code – see the last line. var_dump would be better 😉 and would give you the db results queried. )

I’ll try var_booty next time. 😂

TTFB is speedy — 93.8ms. So if TTFB is fast on these little test files—is there something weird with my Craft install?

(the var_rump thing is a typo in Matt’s suggested code – see the last line. var_dump would be better 😉 and would give you the db results queried. )

Out of interest, is anyone also experiencing this problem using CloudFlare’s 1.1.1.1 DNS in macOS? You set it in Sys Prefs > Network > Advanced > DNS: DNS Servers.

Since removing CloudFlare’s servers all my Craft sites on Valet have gone from 20-30 second load times to less than a second or two (depending on the site). This may be a coincidence so I’ll keep an eye on what happens.

Last night I found Cloudflare’s DNS was causing delays in everything using it. Seems to be moderately better this morning.

My preferred way of controlling external DNS when Valet is installed is to create custom dnsmasq configs for the various providers I might use is documented here: https://github.com/laravel/valet/issues/736#issuecomment-572687589 (and then MacOS’s DNS server list is just 127.0.0.1 so dnsmasq can provide it when needed, with fewer timeouts)

I have separate configs I enable/disable for Cloudflare, OpenDNS, Google, etc. I normally prefer cloudflare’s 1.1.1.1 … until last night’s incident.


EDIT: Update: The CloudFlare issue was very temporary.

I’ve been having this exact same problem. Everything is up to date, including Craft CMS, and I have a beefy 2019 MBP.

Out of interest, is anyone also experiencing this problem using CloudFlare’s 1.1.1.1 DNS in macOS? You set it in Sys Prefs > Network > Advanced > DNS: DNS Servers.

Since removing CloudFlare’s servers all my Craft sites on Valet have gone from 20-30 second load times to less than a second or two (depending on the site). This may be a coincidence so I’ll keep an eye on what happens.

https://github.com/laravel/valet/blob/12f75fc2a8286030eb149ab43a1cf10a5a0c29b6/cli/valet.php#L252

OK, so valet stop does two things: stop Nginx and stop PHP.

Curiously, my nginx and php processes run as root, not mattstauffer, so i wonder whether trust is at play here.

I’m showing nginx as correctly stopping when I run valet stop but php keeps running, for whatever good that does.

So let’s dig into what Valet telling nginx to stop does:

https://github.com/laravel/valet/blob/12f75fc2a8286030eb149ab43a1cf10a5a0c29b6/cli/Valet/Nginx.php#L159

runs sudo brew services stop nginx

And what it telling PHP to stop does:

https://github.com/laravel/valet/blob/12f75fc2a8286030eb149ab43a1cf10a5a0c29b6/cli/Valet/PhpFpm.php#L125

brew -> stopService ->all running services which start with php. In your case, this should run

sudo brew services stop php

… which doesn’t seem to have any impact on your computer.

I just noticed something. If I try to run that same command:

image

So if my services are started as mattstauffer and then Valet tries to stop them with sudo it throws an error. If I stop them manually and then valet start again, now they’re started as root.

I can’t imagine how that would solve this mysterious problem, but hey, at least it might get your computer into a more predictable state?

I have been suffering with a slow Valet setup, thinking the problem was that WordPress was slow all along. I just tried a different set up (not Valet), and now I get response within 0.1s instead of 2s with Valet. I know that I’m not giving enough information to be helpful to Valet developers, but I did want to help lurkers and encourage them to investigate not just your PHP application, but also your setup.

my iMac is new and super specced so wasn’t the issue. Fortunately, I have found and resolve the issue though. Was down to a plugin and some missing elements on my side.

Had a related issue with a 2011 mac and high sierra: Basically dnsmasq didnt start up. I just installed valet.

So I did this: brew services stop dnsmasq sudo brew services stop dnsmasq valet restart

That fixed it

@circa42 Could you try loading a site with just a straight HTML file?

Then one with a single PHP file that doesn’t do anything?

<?php

echo "Hey there!";

Then, if it’s easy enough, one that just connects to your database?

<?php

$host = '127.0.0.1';
$username = 'root';
$password = '';
$database = 'testing_valet';
$table = 'users';

$mysqli = new mysqli($host, $username, $password, $database);

if ($mysqli->connect_errno) {
    echo "Error: Failed to make a MySQL connection:<br>";
    echo "Errno: " . $mysqli->connect_errno . "<br>";
    echo "Error: " . $mysqli->connect_error . "<br>";

    exit;
}

$sql = "SELECT * FROM {$table}";

if (! $result = $mysqli->query($sql)) {
    echo "Error: Failed querying<br>";
    echo "Errno: " . $mysqli->errno . "<br>";
    echo "Error: " . $mysqli->error . "<br>";
    exit;
}

var_rump($result->fetch_assoc());