这是最近一直困扰我的问题。我似乎无法确定是什么原因造成的,它发生在本地和我的实时服务器上。这是发生的事情的要点。
我执行(例如)AJAX 调用。我可以继续每秒执行相同的调用,并且它发生的速度与您期望的一样快。但每隔 30-60 秒,呼叫就会挂起大约 30 秒,然后重新启动。
注意:这不仅仅是 ajax 调用,新页面加载时也会发生同样的情况。直接访问路线(不通过前端)时也会发生这种情况,但我更容易测试并向您展示以下视频:
https://www.youtube.com/watch?v=Cg-rd8FAAog
这种情况会发生在任何请求上,而不仅仅是特定的请求,它看起来完全是随机的。
服务器打开请求,挂起大约 30 秒,然后最终将关闭它,如下所示:
编辑上面的图片: 调试器的第二张照片显示了我尚未简化的大量代码。我简单地使用下面的测试用例进行了尝试,得到了完全相同的 30 秒左右的延迟,调试栏上只显示了一个查询。
public function(Request $request){
return response()->json([], 200);
}
我检查了一些具体的示例,在整个(大约)30 秒内,控制器函数中没有任何代码执行,然后,当它决定执行时,它只会在几毫秒内执行所有代码 - 就像它应该的那样。
如上所述,这发生在我的本地计算机和实时服务器上。
我已经完成了 Composer dump-autoload 和 php artisan 优化,但这没有什么区别。
令人困惑的是,该网站在运行时非常好且快速 - 但它只是随机挂起。
有人知道这里发生了什么吗?您以前经历过类似的事情吗?我还可以进行更多调试来找出它挂起的位置/原因吗?
这是我的作曲家文件:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"barryvdh/laravel-dompdf": "^2.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "7.4.1",
"intervention/image": "^2.7",
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.5",
"laravel/ui": "^3.3",
"league/flysystem-aws-s3-v3": "^1.0",
"league/flysystem-cached-adapter": "~1.0",
"league/flysystem-sftp": "~1.0",
"maatwebsite/excel": "^3.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "3.6.6",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "1.4.4",
"nunomaduro/collision": "5.10",
"phpunit/phpunit": "9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
好吧,我似乎终于解决了这个问题。 storage/framework/sessions 文件夹中有超过 220,000 个文件!我清除了所有这些,现在一切看起来都很好。我还修改了会话超时以阻止这种情况再次发生。
更新:
会话文件没有被覆盖,新的文件正在创建。注释掉 $middleware 中的 SessionStart::class 似乎已经解决了这个问题(将其留在 $middlewareGroups 中)
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \Illuminate\Session\Middleware\StartSession::class, <------ commented this out
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'checkPermission' => \App\Http\Middleware\CheckPermission::class,
];
}