dev_appserver.py 的托管项目与部署到 Google 云的结果不同

Hosting project with dev_appserver.py gives different results to deploying to Google Cloud

该项目旨在获取一些用户输入并检查连接的 Google 数据存储是否匹配。使用 dev_appserver.py 托管时一切正常。

现场版不是这样,用gcloud app deploy上传。尝试检索实体时出现问题,将其键用于 lookup.

<?php
require __DIR__ . "/vendor/autoload.php";

use Google\Cloud\Datastore\DatastoreClient;

$datastore = new DatastoreClient([
"projectId" => "54327567209-project"
]);

// Retrieving user entities
function lookup_user(DatastoreClient $datastore, string $id) {
  $key = $datastore->key("user", $id);
  $user = $datastore->lookup($key);
  return $user;
}

// Validation
$authErr = "";
$id = $pword = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // Existence check
  if (!empty($_POST["id"]) && !empty($_POST["password"])) {
    $id = $_POST["id"];
    $pword = $_POST["password"];
    // Attempt to get user from Google Cloud
    $user = lookup_user($datastore, $id); // <---- Error happens here
    // Check if user exists and password matches
    if (!empty($user["name"]) && $user["password"] == $pword) {
      // Removed for debugging
    } else {
      // Id or password authentication fail
      $authErr = "User id or password is invalid";
    }
  } else {
    // Missing id or password
    $authErr = "User id or password is invalid";
  }
}
?>

<!DOCTYPE html>
<html>
  <head>
    <style>
      .error {color: #FF0000;}
    </style>
  </head>
  <body>
    <h2>Account Access</h2>
    <form method="post" action="">
      <div>Username: <input name="id" type="text"></input></div>
      <div>Password: <input name="password" type="password"></input></div>
      <div><input type="submit" value="Login"></div>
      </br>
      <span class="error"><?php echo $authErr; ?></span>
    </form>
  </body>
</html>

页面在尝试进行查找时变为空白,类似于 运行 exit()。我看不到任何错误消息。我想知道是否可以打开某种日志记录来帮助解决这个问题。

问题出在 lookup_user() 函数上。删除此函数并粘贴相同的内联代码解决了该问题。