Very slow response if there is an error in laravel view or component - php

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

Related

View [admin.sellers.show] not foun | Illuminate/View/FileViewFinder.php | line 137

I deploy laravel 5.8 project on server, then when I was tryng to make delete request got this error
the project work fine on the local
this error show on another pages when it tring to make request delete request ,
View [admin.contacts.show] not found.
View [admin.brands.show] not found
php version : v7.4.33
I run this commands in server terminal
php artisan cache:clear
php artisan view:clear
php artisan config:cache
it still show the same error
note : I tried to deploy the same project on another server , I got the same error but it fixed with the previes command.
so did I miss something in the first server ?
here is my answer for my question , It's not one issue but 2 issues
first one is caching views , routes , and config
make sure to run this commands after each edit on the server.
php artisan view:cache
php artisan route:cache
php artisan config:cache
then for some reason my server delete request was not working
why I don't know, because of that the project was working fine locally and fine on another server .. after tens times of edits and tests with no real results because of app caching I didn't not that after a long time of trying and testing, and debugging.
I realized that in my server delete request is called the show method which is like destroy method URL https://url/sellers/{id} but with the get method, so, and show method has this unknown view.
in the end, I used the cache command after each time I made an edit on the server and changed the delete request to post request with pass _method: 'delete' as body request and it's fixed.
note: delete request may work on another server because it's works on my second server
my test :
delete request only
response
delete request with _method:'delete'
request body
response
finaly with post request and _method: 'delete'
request body
response
done

PHP - Laravel error : Symfony\Component\Finder\Exception\DirectoryNotFoundExceptionon my cPanel

I mistakenly ran my laravel application on debug mode in my production environment, and it threw an error for me to change App_debug:true to App_debug:false, which I did, ever since then, my site has been throwing an HTTP ERROR 500
"This page isn’t working admin.robyhub.com is currently unable to handle this request.
HTTP ERROR 500"
I then went on to my cpanel terminal and tried to clear the logs on the config file but it gives me the below error.
[thehcerl#premium261 admin.robyhub.com]$ php artisan config:clear
Symfony\Component\Finder\Exception\DirectoryNotFoundException
The "/home/thehcerl/admin.robyhub.com/resources/lang/ha" directory does not exist.
at vendor/symfony/finder/Finder.php:590
586▕ } elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
587▕ sort($glob);
588▕ $resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
589▕ } else {
➜ 590▕ throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
591▕ }
592▕ }
593▕
594▕ $this->dirs = array_merge($this->dirs, $resolvedDirs);
+2 vendor frames
3 app/Providers/TranslationServiceProvider.php:40
Illuminate\Support\Facades\Facade::__callStatic()
4 app/Providers/TranslationServiceProvider.php:27
App\Providers\TranslationServiceProvider::phpTranslations()
Cpanel Terminal
Ever since I changed debug to false on my .env from my laravel project main directory because the laravel documentation warned me to not use debug mode on a non-local environment. I expected my application would automatically stop receiving the laravel debug config solutions and would run properly.
This is not a very generic error, it's as a result of an error on my part, I created language folders that I did not link to my PHP "translationProvider.php" file, so it invariably gave me that issue.
I was using a purchased template from Envato so I hadn't taken the time to get the full inner working of the backend at the time.
If anyone has a similar error I hope this will guide you not to make the mistakes I made, and meticulously look through your code when making changed or edits.
Thanks, happy coding.

Laravel 8.x returns status code 200 instead of 404 when throwing NotFoundHttpException

After upgrading to Laravel 8.9 from 7.x, Laravel returns the wrong status code when requesting a non existing model. The response body itself contains the expected error response, however the status code is 200. Here is the corresponding controller code:
public function findOne($eventId)
{
$event = Event::withMailRecords()->withContacts()->withContingents()->findOrFail($eventId);
return new EventResource($event);
}
I only get the wrong status code when starting the server using php artisan serve and then execute our frontend tests to query the server. Within our Laravel HTTP tests, everything works fine. Moreover, the issue only appears within our bitbucket ci pipeline. Locally everything works fine, even when executing the tests within our pipeline image.
I cannot see any environment differences that could possibly result in this behavior.
Maybe this is not the source of your problem, but are you sure there is no space before any "<?php" tag or that you are not using encoding like UTF8 with BOM that would have already sent headers ?

`php artisan down` throws uncaught 503 and yields an error page

Edit: Accepted Issue on GitHub https://github.com/octobercms/october/issues/2830
I am using OctoberCMS which is based upon the Laravel PHP framework.
(I am a newbie to both).
Ultimately, I'm trying to script as much of the site update process as possible. That is, update/upgrade the testing and live sites and upload my new code. This entails being able to put the site into maintenance mode from the command line.
The top level directory for my website (/var/www/website/) contains the artisan php script.
Running php artisan list I get:
Available commands:
down Put the application into maintenance mode
up Bring the application out of maintenance mode
Within the OctoberCMS backend I can put the frontend into maintenance mode, and the chosen maintenance page is shown as expected.
When I enter php artisan down in the console I get Application is now in maintenance mode., as expected. But when I reload the website, I get the following error:
We're sorry, but an unhandled error occurred. Please see the details below.
.../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php line 41
Type: Undefined
Exception: Symfony\Component\HttpKernel\Exception\HttpException
\*
\* #throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance()) {
throw new HttpException(503);
}
return $next($request);
}
It would appear that Laravel/Symfony is doing what it should and throwing a 503 Service Unavailable, but there is nothing to catch it and render the maintenance page.
So, two questions
1) Is this a bug? If so, in Laravel or October? Or have I done something wrong -- config setting...?
2) Assuming it won't be 'fixed' any time soon, how and where should I catch the HttpException(503) and yield the maintenance page?
There is what might be an answer in Stackoverflow > '503 can't be overridden in L5.1', which appears to suggest editing/overriding public function handle($request, Closure $next) with a try/catch/return-if-503 sequence. But is it a good idea to override a function of the CMS/framework? If so, how and where?
I have read OctoberCMS > docs > services > Errors & Logging and, despite hoping for an easier solution, I would create a Plugin to solve the problem if that is the best/only/ideal way. Although creating a Plugin to catch what should surely already be caught seems overkill.
This looks to be the way to do it Laravel - Pass arguments to php artisan down, but I'm not confident to attempt it.
Turnkey LAMP 14.1 server
October system build 414
php --version
PHP 5.6.30-0+deb8u1 (cli) (built: Feb 8 2017 08:50:21)
php artisan --version
Laravel Framework version 5.1.46 (LTS)

Yii can't find GearmanClient

I am trying to create tasks using gearman using GearmanClient class from the gearman-php-extensions. I am able to run below program using command prompt-
//php client.php works fine
<?php
$client= new GearmanClient();
$client->addServer();
$task = $client->do("send", "hi");
?>
But I wan't to run this code in some yii controller. It seems like yii is not able to find the path upto GearmanClient class, but why?
Also I am writing the yii programs in eclipse. As php command and eclipse are both using the same php library, my yii controller should work fine. Instead my browser gives errors like-
PHP warning
include(GearmanClient.php): failed to open stream: No such file or directory
#plus some warnings and the yii stack trace.
This is happening because, the process that is handling the php files is not updated with the latest php.ini configuration. So you just need to restart that process.
Therefore:
If php handler is running as a web server module, then you'll need to restart the web server.
If you have php running as a cgi process, then you'll need to restart that process.

Categories