1

I'm new to laravel and I'm building a pure laravel 9 app(no vue, nodejs or other frameworks just laravel + vanilla js). If I have any kind of error in any laravel view/component/partials the error page response tooks more then 20seconds to appears. If I have an error in any controller/model/config or other laravel's environment files, the same error is superfast. In example if I have a typo in my view layout.blade.php

PHP

@php
ech 'missing a letter';
@endphp

this will throw the error in 20 seconds

if I place a typo in a controller like this

PHP

public function index() {
    retur 'missing a letter';
}

this will throw the error instantly.

if this can helps, checking in my console the laravel log file like this

DEBIAN BASH

tail -f /var/www/mylaravelapp/storage/logs/laravel.log

will throw the error in the same time that appears in the laravel error page. Obviuously is not a big deal, but since I'm working on the appareance of the UI, this will slow down my work so much.

UPDATE

I'm adding a screen of my devtools opened, it simply waits for server response 23 seconds enter image description here

UPDATE

Some new details, really strange for me, what happens is that in my component I have some pure javascript script in the bottom of the page(around 500 rows). If I delete the scripts the error page will run superfast. I tried to place the scripts directly behind the scripts tags and I tried using the @pushOnce directive with same results. I tried to reduce the amount of code, and the more I reduce the code the more will run faster. I tried to put the script directly in my layout.blade.php that calls the component and it runs superfast, I tried to put the js code like an external script and it runs superfat, so problem happens only with inline JS probably I'm placing the scripts in a wrong way

UPDATE

OK I think this update is important, if I run my laravel app through my apache web server(so not using php artisan) the error page will load superfast, so this cannot be related to some code error. Usually I run my laravel app in this way

php artisan serve --host 192.168.25.209

where 192.168.25.209 is a server in my network that is hosting my laravel app. As @Don't Panic pointed in the comments

"The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked"

So I checked for permissions on cache storage folders, but everything looks good, cache files and logs are correctly written

silvered.dragon
  • 407
  • 1
  • 7
  • 19
  • How fast is view returned when you don't have an error? – NoOorZ24 Aug 16 '22 at 09:03
  • superfast around 100ms without any caching envrionment and e couple of libraries loaded (font awesome and axios ) – silvered.dragon Aug 16 '22 at 09:08
  • Not a solution but for text output in blade files you should use `{{ $variable }}` – NoOorZ24 Aug 16 '22 at 09:16
  • is the same, I just reported the echo example for making things easier – silvered.dragon Aug 16 '22 at 09:19
  • Try using something like `info('test')` in your controller. Is it fast or slow? If slow then problem could be related to file writing – NoOorZ24 Aug 16 '22 at 09:31
  • Does browser devtools show any clues, eg are there some remote resources timing out on the error page or something like that? Are your files on a network drive, or mounted somehow unusually, anything like that? Anything special about the `storage/` dir (where logs and caches etc are written)? – Don't Panic Aug 16 '22 at 10:04
  • @NoOorZ24 is superfast! only errors are slow. – silvered.dragon Aug 16 '22 at 10:17
  • @Don'tPanic I added a screen of my devtools, I'm serving with php artisan serve ther is no cache environment, the files are on a virtual machine in my network with host 192.168.25.209. The files can be written very fast, because the problem happens only with views, if I have an error in the controller is superfast. – silvered.dragon Aug 16 '22 at 10:26
  • Not sure what "*the files are on a virtual machine in my network*" means exactly, but that sounds like a big red flag to me, at least something to test. Try hosting files locally, see if the problem persists. – Don't Panic Aug 16 '22 at 10:33
  • can you clear `view cache` and test the time taken for the page load when there is no error. `php artisan view:clear` – iamab.in Aug 16 '22 at 10:38
  • @Don'tPanic simply I have phisical servers in my company, one of those servers is a vmware host, on this host there is dedicate debian VM that I can access through my local network. On this VM there is my laravel App. How can this be a red flag for you? How can you deploy webapps if you work only on your local machine? Everything works superfast except the errors in views. For me it looks like a giant loop somewhere in my app. – silvered.dragon Aug 16 '22 at 10:42
  • @iamab.in I did it and it tooks around 250ms(including font awesome and axios cdn) – silvered.dragon Aug 16 '22 at 10:47
  • :-) "*the files are on a virtual machine*" makes it sound like files are not on the same machine as the web server, a sure way to see strange performance issues. – Don't Panic Aug 16 '22 at 10:54
  • @Don'tPanic sorry maybe I didn't explain myself well, I meant the whole development environment (LAMP server + laravel files) – silvered.dragon Aug 16 '22 at 10:59
  • I added an update regarding how javascript impacts the error page performance – silvered.dragon Aug 16 '22 at 15:35
  • You mentioned "*ther is no cache environment*" - Laravel has caching bulit in, you can see the config in `config/cache.php`. If you haven't touched it, by default it will be using file caching, and reading/writing to files on disk under `storage/framework/`. Do you see (current) files in there? There are many examples here on SO of mis-configured cache, or other cache-related problems causing slow performance. Might be worth investigating, if you haven't already. – Don't Panic Aug 17 '22 at 08:05
  • @Don'tPanic I cleared the cache already as you suggested, and investigated cache problems bu I think this update is important, if I run my laravel app through my apache web server(so not using php artisan) the error page will load superfast, so this cannot be related to some code error or laravel misconfiguration. Usually I run my laravel app in this way `php artisan serve --host 192.168.25.209` where 192.168.25.209 is the server in my network that is hosting my laravel app – silvered.dragon Aug 17 '22 at 09:09
  • I didn't suggest clearing cache, I wondered if there is a problem reading/writing to the cache files on disk (or whatever cache you have configured). Checking [the PHP docs](https://www.php.net/manual/en/features.commandline.webserver.php) about the built in server, they say: "*The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked*". So maybe that's the only problem, eg https://stackoverflow.com/questions/54946340/should-i-rely-on-php-artisan-serve-for-a-locally-based-project – Don't Panic Aug 17 '22 at 09:28
  • @Don'tPanic I can clearly see the creation of cache files under folder /var/www/html/disponibilita/storage/framework/cache and /var/www/html/disponibilita/storage/framework/views in both artisan and apache environment. I really cannot figure out what is happening. – silvered.dragon Aug 17 '22 at 09:40

0 Answers0