theredforest
theredforest

Reputation: 497

Slim 3 - Error 500 when calling routes in parallel

I have deployed my angular application in a shared hosting server and I keep getting an error 500 whenever by angular app sends a multiple requests to the same route prefix. My routes in slim 3 are structured flat like these:

$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){ ... }

In my angular app, I am using $q.all() method to call requests simultaneously.

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);

In this requests, 4 of them are calling from the same route prefix. Like:

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

The errors are inconsistent sometimes it will throw error 500 on /events/{id} and sometimes in these two, /events/{id}/players and /events/{id}/teams. It seems there is a maximum number of requests per route prefix (I'm not sure), and if there is, how can I increase that in slim 3?

Upvotes: 1

Views: 214

Answers (1)

Jeremy Hamm
Jeremy Hamm

Reputation: 499

Wherever you instantiate your slim app, add the below filename and rule to your .htaccess file. This will direct api traffic to the router when the routes are called.

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

Try adding the following to your .htaccess file

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

Upvotes: 0

Related Questions