Slim 3 - 并行调用路由时报错500

Slim 3 - Error 500 when calling routes in parallel

我已经在共享主机服务器上部署了我的 angular 应用程序,每当 angular 应用程序向同一路由前缀发送多个请求时,我总是收到错误 500。我在 slim 3 中的路线结构扁平,如下所示:

$app->get('/players', function($request, $response, $args){ .. }
$app->post('/players', function($request, $response, $args){ ... }
$app->post('/players-exists', function($request, $response, $args){ ... }
$app->post('/players/create', function($request, $response, $args){ ... }
$app->get('/players/stats', function($request, $response, $args){ ... }
$app->post('/players/{id:[0-9]+}', function($request, $response, $args){ ... }
$app->get('/players/{id:[0-9]+}', function($request, $response, $args){ ... }
$app->get('/players/{id:[0-9]+}/stats', function($request, $response, $args){ ... }
$app->get('/players/{id:[0-9]+}/ranking', function($request, $response, $args){ ... }

在我的 angular 应用程序中,我使用 $q.all() 方法同时调用请求。

var promises = {
    event: eventService.getEvent($stateParams.eventId),
    scorers: eventService.getEventScorers($stateParams.eventId),
    eventOwners: userService.getUsersLite('', roles.TEAM_ADMIN),
    games: gameService.getGames(vm.model.gameListContext),
    teams: eventService.getEventTeams($stateParams.eventId),
    players: eventService.getEventPlayers($stateParams.eventId)
};

$q.all(promises).then(mgr.onLoadAllPromises);

在这个请求中,有 4 个是从相同的路由前缀调用的。喜欢:

/events/{id}
/events/{id}/scorers
/events/{id}/players
/events/{id}/teams

错误不一致,有时会在 /events/{id} 上抛出错误 500,有时在 /events/{id}/players 和 /events/{id}/teams 上抛出错误 500。似乎每个路由前缀有最大请求数(我不确定),如果有,我如何在 slim 3 中增加它?

无论您在哪里实例化您的超薄应用程序,请将以下文件名和规则添加到您的 .htaccess 文件中。这将在调用路由时将 api 流量定向到路由器。

// SlimApp.php
require_once '../vendor/autoload.php';
$app = new \Slim\App();
$app->run();

尝试将以下内容添加到您的 .htaccess 文件

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(/.*)?$ SlimApp.php [QSA,L]