【问题标题】:While Running PHP Script for DynammoDB on AWS it gives 500 Error在 AWS 上为 DynammoDB 运行 PHP 脚本时出现 500 错误
【发布时间】:2018-03-22 03:25:21
【问题描述】:

这是我在 AWS 服务器上在线使用的脚本:

<?php

require './awsPackage/aws-autoloader.php';
use \Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Exception\DynamoDbException;

$tableName = "table_name";

$ddb = DynamoDbClient::factory(array(
    'region'   => 'us-west-2',
    'version'  => 'latest',
    'credentials' => array('key' => '<my_key>',
    'secret' => '<my_secret_key>'))); // EC2 role security

    try {
        $result = $ddb->describeTable(array(
            "TableName" => $tableName
        ));
    } catch (ResourceNotFoundException $e) {
        // if this exception is thrown, the table doesn't exist
        return false;
    }

    echo "<pre>";
    print_r($result);
    echo "</pre>";

    if ($tableName == $result['Table']['TableName'])
        {
            echo $result['Table']['TableName'].": ".$result['Table']['TableStatus'];
        }

    else
        {
            echo $tableName." INACTIVE";
        }

?>

我正在使用此代码检查在线 AWS 服务器上的 DynammoDB 中是否存在提供的表。

设置本地服务器后,此代码在 Windows 上运行良好。

但是当我在线制作这段代码时。它加载页面,然后给出 500 的错误。可能是什么原因?

这是错误日志:

[Wed Mar 21 18:54:19.043570 2018] [:error] [pid 2831] [client 49.35.89.185:1410] PHP Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /var/www/html/test/awsPackage/Aws/Api/DateTimeResult.php:19\nStack trace:\n#0 /var/www/html/test/awsPackage/Aws/Api/DateTimeResult.php(19): DateTime-&gt;__construct('2018-03-21T12:4...')\n#1 /var/www/html/test/awsPackage/Aws/Api/Parser/JsonParser.php(49): Aws\\Api\\DateTimeResult::fromEpoch(1521636246.401)\n#2 /var/www/html/test/awsPackage/Aws/Api/Parser/JsonParser.php(24): Aws\\Api\\Parser\\JsonParser-&gt;parse(Object(Aws\\Api\\TimestampShape), 1521636246.401)\n#3 /var/www/html/test/awsPackage/Aws/Api/Parser/JsonParser.php(24): Aws\\Api\\Parser\\JsonParser-&gt;parse(Object(Aws\\Api\\Struct in /var/www/html/test/awsPackage/Aws/Api/DateTimeResult.php on line 19

【问题讨论】:

  • 查看网络服务器错误日志 500 错误通常意味着灾难性的 PHP 错误
  • 在哪里可以找到该日志?
  • 我会查看 AWS 文档
  • 好的。谢谢,我知道了,我在var/log/httpd/
  • @RiggsFolly 我用错误日志更新了问题。请看一下。

标签: php amazon-web-services amazon-s3 amazon-ec2 amazon-dynamodb


【解决方案1】:

您需要检查 php.ini 文件是否包含有效的date.timezone

例如这样的事情

date.timezone = "UTC"

或者查看有效timezones的列表

【讨论】:

    【解决方案2】:

    根据错误消息,始终设置 data.timezone 值非常重要。否则,如果未定义此值,PHP 将: 您可以通过代码设置它 - 运行时间

    ini_set("date.timezone", "America/New_York");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 2017-02-06
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      相关资源
      最近更新 更多