title: Connecting to Cloud SQL from App Engine is slower than from localhost
body: <p>So I've been trying to connect to Google Cloud SQL from my Google App Engine. Everything works, but the latency is very high. A simple select query is taking about 1.3 seconds. However, when I connect from localhost, it takes a much shorter time. The difference in connection is the following:</p>
  
  <p>in App Engine yaml</p>
  
  <pre><code>MYSQL_DSN: /cloudsql/instanceName
  MYSQL_USER: user
  MYSQL_PASSWORD: password
  MYSQL_DATABASE: dbname
  </code></pre>
  
  <p>in App Engine php</p>
  
  <pre class="lang-php prettyprint-override"><code>$servername = getenv('MYSQL_DSN');
  $username = getenv('MYSQL_USER');
  $password = getenv('MYSQL_PASSWORD');
  $dbname = getenv('MYSQL_DATABASE');
  $connection = new mysqli(null, $username, $password, $dbname, null, $servername);
  </code></pre>
  
  <p>when connecting to Cloud SQL in localhost I use:</p>
  
  <pre class="lang-php prettyprint-override"><code>$servername = "ip.address";
  $username = getenv('MYSQL_USER');
  $password = getenv('MYSQL_PASSWORD');
  $dbname = getenv('MYSQL_DATABASE');
  $connection = new mysqli($servername, $username, $password, $dbname);
  </code></pre>
  
  <p>When connecting from localhost, I have authorized my computer's ip address in my Cloud SQL dashboard, so connecting directly through ip address is no problem. My problem now is that when I am running my php files from localhost to connect to Cloud SQL, the latency is lower than when connecting from App Engine. Any idea why and how I can fix this? </p>