概述
Perform Self-Diagnosis Tests On Your Laravel Application
This package allows you to run self-diagnosis tests on your Laravel application. It comes with multiple checks out of the box and allows you to add custom checks yourself.
Here is an example output of the command:
Included checks
Is the APP_KEY set?
Are your composer dependencies up to date with the composer.lock file?
Do you have the correct PHP version installed?
Do you have the correct PHP extensions installed?
Can a connection to the database be established?
Do the storage and bootstrap/cache directories have the correct permissions?
Does the .env file exist?
Is the maintenance mode disabled?
Are the required locales installed on the system?
Are there environment variables that exist in .env.example but not in .env?
Are there any migrations that need to be run?
Is the storage directory linked?
Can Redis be accessed?
Development environment checks
Is the configuration not cached?
Are the routes not cached?
Are there environment variables that exist in .env but not in .env.example?
Production environment checks
Is the configuration cached?
Are the routes cached?
Is the xdebug PHP extension disabled?
Is APP_DEBUG set to false?
Are certain servers reachable?
Are certain supervisor programs running?
Installation
You can install the package via composer:
composer require beyondcode/laravel-self-diagnosis
If you're using Laravel 5.5+ the SelfDiagnosisServiceProvider will be automatically registered for you.
Usage
Just call the artisan command to start the checks:
php artisan self-diagnosis
Customization
You can publish the configuration file, that contains all available checks using:
php artisan vendor:publish --provider=BeyondCode\SelfDiagnosis\SelfDiagnosisServiceProvider
This will publish a self-diagnosis.php file in your config folder. This file contains all the checks that will be performed on your application.
return [
/*
* A list of environment aliases mapped to the actual environment configuration.
*/
'environment_aliases' => [
'prod' => 'production',
'live' => 'production',
'local' => 'development',
],
/*
* Common checks that will be performed on all environments.
*/
'checks' => [
BeyondCodeSelfDiagnosisChecksAppKeyIsSet::class,
BeyondCodeSelfDiagnosisChecksCorrectPhpVersionIsInstalled::class,
BeyondCodeSelfDiagnosisChecksDatabaseCanBeAccessed::class => [
'default_connection' => true,
'connections' => [],
],
BeyondCodeSelfDiagnosisChecksDirectoriesHaveCorrectPermissions::class => [
'directories' => [
storage_path(),
base_path('bootstrap/cache'),
],
],
BeyondCodeSelfDiagnosisChecksEnvFileExists::class,
BeyondCodeSelfDiagnosisChecksExampleEnvironmentVariablesAreSet::class,
BeyondCodeSelfDiagnosisChecksLocalesAreInstalled::class => [
'required_locales' => [
'en_US',
'en_US.utf8',
],
],
BeyondCodeSelfDiagnosisChecksMaintenanceModeNotEnabled::class,
BeyondCodeSelfDiagnosisChecksMigrationsAreUpToDate::class,
BeyondCodeSelfDiagnosisChecksPhpExtensionsAreInstalled::class => [
'extensions' => [
'openssl',
'PDO',
'mbstring',
'tokenizer',
'xml',
'ctype',
'json',
],
'include_composer_extensions' => true,
],
BeyondCodeSelfDiagnosisChecksStorageDirectoryIsLinked::class,
],
/*
* Environment specific checks that will only be performed for the corresponding environment.
*/
'environment_checks' => [
'development' => [
BeyondCodeSelfDiagnosisChecksComposerWithDevDependenciesIsUpToDate::class => [
'additional_options' => '--ignore-platform-reqs',
],
BeyondCodeSelfDiagnosisChecksConfigurationIsNotCached::class,
BeyondCodeSelfDiagnosisChecksRoutesAreNotCached::class,
],
'production' => [
BeyondCodeSelfDiagnosisChecksComposerWithoutDevDependenciesIsUpToDate::class => [
'additional_options' => '--ignore-platform-reqs',
],
BeyondCodeSelfDiagnosisChecksConfigurationIsCached::class,
BeyondCodeSelfDiagnosisChecksDebugModeIsNotEnabled::class,
BeyondCodeSelfDiagnosisChecksPhpExtensionsAreDisabled::class => [
'extensions' => [
'xdebug',
],
],
BeyondCodeSelfDiagnosisChecksRedisCanBeAccessed::class => [
'default_connection' => true,
'connections' => [],
],
BeyondCodeSelfDiagnosisChecksRoutesAreCached::class,
BeyondCodeSelfDiagnosisChecksServersArePingable::class => [
'servers' => [
'www.google.com',
['host' => 'www.google.com', 'port' => 8080],
'8.8.8.8',
['host' => '8.8.8.8', 'port' => 8080, 'timeout' => 5],
],
],
BeyondCodeSelfDiagnosisChecksSupervisorProgramsAreRunning::class => [
'programs' => [
'horizon',
],
'restarted_within' => 300, // max seconds since last restart, 0 to disable check
],
],
],
];
Available Configuration Options
The following options are available for the individual checks:
BeyondCodeSelfDiagnosisChecksComposerWithDevDependenciesIsUpToDate
additional_options (string, optional parameters like '--ignore-platform-reqs'): optional arguments for composer
BeyondCodeSelfDiagnosisChecksComposerWithoutDevDependenciesIsUpToDate
additional_options (string, optional parameters like '--ignore-platform-reqs'): optional arguments for composer
BeyondCodeSelfDiagnosisChecksDatabaseCanBeAccessed
default_connection (boolean, default: true): if the default connection should be checked
connections (array, list of connection names like ['mysql', 'sqlsrv'], default: []): additional connections to check
BeyondCodeSelfDiagnosisChecksDirectoriesHaveCorrectPermissions
directories (array, list of directory paths like [storage_path(), base_path('bootstrap/cache')], default: []): directories to check
BeyondCodeSelfDiagnosisChecksLocalesAreInstalled
required_locales (array, list of locales like ['en_US', 'en_US.utf8'], default: []): locales to check
BeyondCodeSelfDiagnosisChecksPhpExtensionsAreDisabled
extensions (array, list of extension names like ['xdebug', 'zlib'], default: []): extensions to check
BeyondCodeSelfDiagnosisChecksPhpExtensionsAreInstalled
extensions (array, list of extension names like ['openssl', 'PDO'], default: []): extensions to check
include_composer_extensions (boolean, default: false): if required extensions defined in composer.json should be checked
BeyondCodeSelfDiagnosisChecksRedisCanBeAccessed
default_connection (boolean, default: true): if the default connection should be checked
connections (array, list of connection names like ['cache_1', 'cache_2'], default: []): additional connections to check
BeyondCodeSelfDiagnosisChecksSupervisorProgramsAreRunning
programs (array, list of programs like ['horizon', 'another-program'], default: []): programs that are required to be running
restarted_within (integer, max allowed seconds since last restart of programs (0 = disabled), default: 0): verifies that programs have been restarted recently to grab code updates
BeyondCodeSelfDiagnosisChecksServersArePingable
servers (array, list of servers and parameters like ['google.com', ['host' => 'google.com', 'port' => 8080]]): servers to ping
Custom Checks
You can create custom checks, by implementing the BeyondCodeSelfDiagnosisChecksCheck interface and adding the class to the config file. Like this:
use BeyondCodeSelfDiagnosisChecksCheck;
class MyCustomCheck implements Check
{
/**
* The name of the check.
*
* @param array $config
* @return string
*/
public function name(array $config): string
{
return 'My custom check.';
}
/**
* Perform the actual verification of this check.
*
* @param array $config
* @return bool
*/
public function check(array $config): bool
{
return true;
}
/**
* The error message to display in case the check does not pass.
*
* @param array $config
* @return string
*/
public function message(array $config): string
{
return 'This is the error message that users see if "check" returns false.';
}
}
Example Output
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
最后
以上就是要减肥红牛为你收集整理的php自我诊断检查表,在Laravel应用程序上执行自我诊断测试的全部内容,希望文章能够帮你解决php自我诊断检查表,在Laravel应用程序上执行自我诊断测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复