gpt4 book ai didi

PHP Laravel 同时执行多个 ajax 请求会出现 'encryption key' 服务器错误

转载 作者:行者123 更新时间:2023-12-02 08:10:42 25 4
gpt4 key购买 nike

请帮我解决这个简单的 PHP ajax 请求问题,因为它在我的项目中阻碍了我很长时间。

同时向 PHP Controller 发送多个(如 100 个)ajax GET 请求将给出“未指定应用程序加密 key ”。错误。在 Laravel 中,我创建了以下路由器:

<?php
Route::get('/database/abc/load_single/{elementId}','abcController@loadSingle');

abcController 定义为:

<?php
namespace App\Http\Controllers;
class abcController extends Controller{
public function loadSingle($elementId){
return 'abc';
}
}

然后在浏览器中,我同时发送一个ajax GET请求100次:

for (var index=0; index<100; index++){
$.ajax({
type: "GET",
url: urlPrefix + "database/abc/load_single/10001",
});
}

而且输出结果不稳定,100 分中有 5 分(不同)出现服务器错误。在日志文件中它说:

   [2017-11-18 10:31:53] production.ERROR: No application encryption key has been specified. {"exception":"[object] (RuntimeException(code: 0): No application encryption key has been specified. at C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php:42)
[stacktrace]
#0 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php(1035): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(NULL)
#1 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(46): tap(NULL, Object(Closure))
#2 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(24): Illuminate\\Encryption\\EncryptionServiceProvider->key(Array)
#3 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(749): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#4 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(631): Illuminate\\Container\\Container->build(Object(Closure))
#5 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(586): Illuminate\\Container\\Container->resolve('encrypter', Array)
#6 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(721): Illuminate\\Container\\Container->make('encrypter', Array)
#7 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(885): Illuminate\\Foundation\\Application->make('encrypter')
#8 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(813): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
#9 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(780): Illuminate\\Container\\Container->resolveDependencies(Array)
#10 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(631): Illuminate\\Container\\Container->build('App\\\\Http\\\\Middle...')
#11 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(586): Illuminate\\Container\\Container->resolve('App\\\\Http\\\\Middle...', Array)
#12 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(721): Illuminate\\Container\\Container->make('App\\\\Http\\\\Middle...', Array)
#13 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(215): Illuminate\\Foundation\\Application->make('App\\\\Http\\\\Middle...')
#14 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(189): Illuminate\\Foundation\\Http\\Kernel->terminateMiddleware(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\JsonResponse))
#15 C:\\xampp\\htdocs\\blank\\public\\index.php(60): Illuminate\\Foundation\\Http\\Kernel->terminate(Object(Illuminate\\Http\\Request), Object(Illuminate\\Http\\JsonResponse))
#16 {main}
"}
[2017-11-18 10:34:11] production.ERROR: No application encryption key has been specified. {"exception":"[object] (RuntimeException(code: 0): No application encryption key has been specified. at C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php:42)
[stacktrace]
#0 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php(1035): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(NULL)
#1 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(46): tap(NULL, Object(Closure))
#2 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php(24): Illuminate\\Encryption\\EncryptionServiceProvider->key(Array)
#3 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(749): Illuminate\\Encryption\\EncryptionServiceProvider->Illuminate\\Encryption\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#4 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(631): Illuminate\\Container\\Container->build(Object(Closure))
#5 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(586): Illuminate\\Container\\Container->resolve('encrypter', Array)
#6 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(721): Illuminate\\Container\\Container->make('encrypter', Array)
#7 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(885): Illuminate\\Foundation\\Application->make('encrypter')
#8 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(813): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
#9 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(780): Illuminate\\Container\\Container->resolveDependencies(Array)
#10 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(631): Illuminate\\Container\\Container->build('App\\\\Http\\\\Middle...')
#11 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(586): Illuminate\\Container\\Container->resolve('App\\\\Http\\\\Middle...', Array)
#12 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(721): Illuminate\\Container\\Container->make('App\\\\Http\\\\Middle...', Array)
#13 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(138): Illuminate\\Foundation\\Application->make('App\\\\Http\\\\Middle...')
#14 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#15 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#16 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(647): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#17 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(622): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#18 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(588): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#19 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(577): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#20 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#21 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#22 C:\\xampp\\htdocs\\blank\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#23 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(149): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#26 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#29 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#30 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#31 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#32 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#35 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#36 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#37 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#38 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#39 C:\\xampp\\htdocs\\blank\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#40 C:\\xampp\\htdocs\\blank\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#41 {main}
"}

应该有一些我错过了这个问题的配置。请帮我解决这个问题。非常感谢。

最佳答案

首先,确保您的 .env 文件设置了 APP_KEY

现在,如果你真的设置好了,试着运行 php artisan config:cache 来缓存配置。此外,如果您在应用中直接使用 APP_KEY,请确保您使用的是相应的配置键。

关于PHP Laravel 同时执行多个 ajax 请求会出现 'encryption key' 服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47365198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com