Slim Framework on Google App Engine

skeemer • November 13, 2014

archive

Today I launched my first production app on Google App Engine (GAE). I ran into a few headaches along the way, but thanks to the local dev tools, it wasn't nearly as bad as it could have been.

The first headache was that one of the packages I was using utilized Guzzle 3 which requires the cURL extension. It's not there. I had to fork and fix the package.

Here are the tips I figured out for using the Slim Framework.

  1. Add the following because Slim requires it without testing if it exists.

    // Work around for Slim on GAE
    if(!isset($_SERVER['SERVER_PORT'])) $_SERVER['SERVER_PORT'] = 443;
    
  2. If you aren't using your own log writer, the default one uses php://stderr. According to the GAE docs, it appears that this shouldn't be a problem. Not so. I used the following dummy to just throw the messages through error_log(). Somewhere along my fruitless search for answers, I found out those don't output to the same place.

    class DummyLogWriter {
      public function write($message, $level = null) {
        error_log((string) $message);
        return true;
      }
    }
    
    $app = new \Slim\Slim([
        'log.writer' => new DummyLogWriter()
    ]);
    

With those two tweaks, Slim seems to be working well.