1

What I am doing? I am working on google cloud task queue handler. Queues pushed successfully. Google cloud executed these queue internally. I have created app.yaml file where I have written below lines:-

handlers:
  - url: /click_queue
    script : click_queue_result.php

Now I opened command line and run this command "gcloud app deploy". Then my project is deployed on google cloud server. Now I try to make a DB connection but continuously showing error db connection timeout.

I want to access Google cloud Sql Instance in click_queue_result.php

Please give me suggestion how I can resolve it??

<?php
$servername = "IP_ADDRESS";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

When I hit this url https://google-cloud-project-id.appspot.com/click_queue then following error is occurred:-

Connection failed: Connection timed out
4

1 回答 1

2

As described in the Connecting from App Engine documentation and in the GoogleCloudPlatform/php-docs-samples github page, to use Cloud SQL on App Engine for PHP you must either use the provided Unix domain socket or a TCP connection (in the case of an App Engine Flex).

In your case, you won’t be able to connect with the instance’s IP address, instead you need to set its connection name as an environment variable in the app.yaml file. You may refer to the index.php file in the github repository for an example using PDO.


于 2019-07-31T15:17:31.233 回答