Slim 3 - 并行呼叫路由时出现错误500

时间:2017-05-21 03:35:49

标签: php angular q shared-hosting slim-3

我已经在共享托管服务器中部署了我的角度应用程序,并且每当角度应用程序向同一路由前缀发送多个请求时,我都会收到错误500。我在苗条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){ ... }

在我的角度应用程序中,我使用$ 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中抛出错误。似乎每个路由前缀有最大数量的请求(我不确定),如果有,我怎么能在苗条3中增加呢?

1 个答案:

答案 0 :(得分:0)

无论您在何处实例化您的苗条应用,请将以下文件名和规则添加到.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]