douningle7944 2014-07-16 14:37
浏览 85

AWS S3 PHP脚本在从SSH运行时有效,但在浏览器中无法运行

I have a script that links to my AWS S3 service. It's a test script that creates a random bucket and puts a text file in the bucket.

When executed via SSH [root@html] php ./sample.php

it executes without errors, the bucket is create and the file is created in the bucket.

However when I try to run via browser, it stops just before the command line to create the bucket and the script seems to end suddenly. The browser does not display any error message.

I'm not sure what it is that I'm missing out on. I've tried on Safari, IE 9, Chrome and Firefox. All gave a similar result.

Below is the script mentioned above,

<?php
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';

use Aws\S3\S3Client;
$client = S3Client::factory();

$bucket = uniqid("php-sdk-sample-", true);
echo "Creating bucket named {$bucket}
";     <--- This line displayed when run from browser 
$result = $client->createBucket(array('Bucket' => $bucket));

// Wait until the bucket is created
$client->waitUntilBucketExists(array('Bucket' => $bucket));


$key = 'hello_world.txt';
echo "Creating a new object with key {$key}
";
$result = $client->putObject(array(
    'Bucket' => $bucket,
    'Key'    => $key,
    'Body'   => "Hello World!"));


echo "Downloading that same object:
";
$result = $client->getObject(array(
    'Bucket' => $bucket,
    'Key'    => $key));

echo "
---BEGIN---
";
echo $result['Body'];
echo "
---END---

";

?>
  • 写回答

1条回答 默认 最新

  • dqg95034 2014-07-16 14:41
    关注

    Do you have any PHP CLI modules loaded which may make it work from command line but not from your webserver? OR could it be that you have set your AWS credentials which are for the S3Client in your command line environment variables so you must manually enter them when building your S3Client ?

    评论

报告相同问题?

问题事件

  • 专家修改了标签 8月18日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b