Is this a non performant way to do PHP routing?

I have run into this problem with Google App Engine that I’m not quite sure how to solve. I’ve just migrated from AWS (for a myraid of reasons) with my application that was getting great perf numbers. It was doing about 1.5s (give or take) to total interaction. I was pretty happy with that. But since I’ve come over to App Engine (and I’ve changed nothing else in the way I’m rendering my code), my Time to First Byte is 4-7 seconds on all of my pages. I can’t figure out why that is, so I figure it has to be the router. Here is my router code:

<?php declare(strict_types=1); session_start();  require_once 'vendor/autoload.php'; require_once 'model/Api.php';  require_once get_required_php_file(parse_url($  _SERVER['REQUEST_URI'], PHP_URL_PATH));  function get_required_php_file(string $  path): string {      if ($  path === '/') return '404.php';      // you are not allowed to navigate to these files     if (\substr($  path, 0, 6) === '/model' || \substr($  path, 0, 7) === '/vendor') return '404.php';      // clipping the /api off     $  path = \substr($  path, 4);      // just require the index file     if ($  path === '/') return '404.php';      // getting the true php path (no beginning or ending slashes and index.php at the end)     $  full_php_path = \ltrim(\rtrim($  path, '/'), '/').'/index.php';      // returning the path as long as it exists, if it doesn't, return 404.php     return (\file_exists($  full_php_path) ? $  full_php_path : '404.php');  } 

I’ve never written a router before, I’ve always just done it to where you put your index.php under /login/, navigate to login, and your index.php is executed. That is not how App Engine works though, all requests must be routed through a router.

Is my router my performance problem or do I need to look other places?