这是我在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->__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->parse(Object(Aws\\Api\\TimestampShape), 1521636246.401)\n#3 /var/www/html/test/awsPackage/Aws/Api/Parser/JsonParser.php(24): Aws\\Api\\Parser\\JsonParser->parse(Object(Aws\\Api\\Struct in /var/www/html/test/awsPackage/Aws/Api/DateTimeResult.php on line 19
答案 0 :(得分:1)
从错误消息中,始终设置data.timezone值非常重要。否则,如果未定义此值,PHP将:抛出错误(可能在本地关闭错误 - 但不在实时) 您可以通过代码 - 运行时间
进行设置ini_set("date.timezone", "America/New_York");
答案 1 :(得分:1)