Theme template.php functions after bootstrap
While what you are doing could work, this is not what you want to do. If you want to render your menus outside Drupal you should do it a more  robust way to implement this using Drupal best practice etc.

One way would be to


create a public URL that returns the menus. This could return just the data or markup. 
Have you custom code consume the API, so you fetch the data via http instead of manually trying to bootstrap Drupal.


You also need to ask yourself why this custom code lives outside Drupal. If you can bootstrap Drupal etc, the code might as well be part of Drupal via a module.

Boostrapping Drupal yourself is possible but a lot of crazy bugs can show up. Drupal depend on a lot of various stuff like $_GET / $_POST and other stuff that you might forget to handle. Also if you update Drupal this code can easily break as you are using internal functions which can change in various ways.