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

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)

Related

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.

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

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

Cannot debug Laravel HTTP Tests

I have a couple of HTTP tests in a Laravel 5.6 project. I would like to debug the tests and the codepath they call. I can debug the test method but not the actual code. Meaning the debugger doesn't stop at breakpoints in the controller etc.
I'm using Xdebug 2.6.0, PhpStorm 2018.1 and PHP 7.2.
It turns out that the 500 error code came from one of the custom middleware layers and not from the controller. So the breakpoint never got hit because of the error in the middleware layer. I wish that there was an error stack trace instead of only the message "Expected status code 200 but received 500".
I ended up mocking the middleware. Just in case someone is interested how I did it:
$mockMiddleware = Mockery::mock("App\Http\Middleware\MyMiddleware");
$mockMiddleware->shouldReceive("handle")->once()
->andReturnUsing(function ($request, $next) {
return $next($request);
});
App::instance("App\Http\Middleware\MyMiddleware", $mockMiddleware);

Process Component Symfony failed to execute behat command

I'm currently working on a package of Laravel that will launch behats tests directly from our browser. this is a personal project.
I use the Process Component Symfony to execute various commands. However, it can not execute the command Behat and returns me this error:
vendor / bin / Behat "failed.
Exit Code: 255 (Unknown error) Working directory: / Applications / MAMP / htdocs / Package / public
Output: ================ Parse error: parse error, expecting '&' 'or "variable (T_VARIABLE)' 'in / Applications / MAMP / htdocs / Package / vendor /laravel/framework/src/Illuminate/Foundation/helpers.php on line 475
Error Output: ================
In short, he refused to execute all commands Behat. Here the use of the command in the controller of my package.
<? Php
namespace Nkweb\BehatWeb\Http\Controllers;
use App\Http\Controllers\Controller;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class BehatWebController extends Controller
{
    
    public function launchBehat()
    {
        
        $command = base_path('vendor/bin/Behat');
        $process = new Process($command);
        try {
            $process->mustRun();
            $outputs = explode("\n", $process->getOutput());
        } Catch (ProcessFailedException $e) {
            return $e->getMessage();
        }
        return view('behatweb::content.init', ['outputs' => $outputs]);
    }
}
I searched google and returned in every way but I could not find anything about it. I really need your help :(
I'm not a Laravel user but I'll give it a shot. I'll walk through my process so hopefully it will help you debug similar issues in the future. I'm assuming you're using the latest Laravel but would be helpful if you could state which version you're running.
Looking at the error, we have a nice place to start. Line 475 in laravel/framework/src/Illuminate/Foundation/helpers.php. Which is the first line below:
function event(...$args)
{
return app('events')->fire(...$args);
}
And we are expecting a variable or & (pass by reference) according to the error, so we can assume it is talking about the parameter in the event function. Now we can see the parameter is preceded by ... this is a hard one to Google but you might get better results searching for the "splat" operator (note, different languages may have alternative names).
This was introduced in PHP 5.6, which leads me to believe you are running an earlier version which is not supported. I'd suggest upgrading to PHP 5.6 or above and seeing if that fixes your issue. If it doesn't, please post the version of PHP you're using.

Laravel 4 Commands stopped working suddenly

Back from vacation, and when I'm trying to run one of my previously working command:
php artisan list
Throws me:
[root#api2]# php artisan list
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function getArgument() on a non-object","file":"\/var\/www\/html\/api2.alariscms.com\/vendor\/laravel\/framework\/src\/Illuminate\/Console\/Command.php","line":153}}
And I seriously cannot understand why this happens. I tried debugging the file that throws an error. It awaits argument:
InputInterface $input but it gets NULL
I don't know what can go wrong on a framework level to stop receiving the required object.
Any ideas where to start debugging from? Or I can reload configurations / update laravel via cmd?
Thanks
This is what I would do:
php artisan dump
composer dump-autoload
check for current Laravel version
and then go to that specific command and check for bug there.
Also, what kind of argument are you trying to pass to command ? Is that object - if so check where is implementation of that class ?

Categories