Amazon S3 Bucket url's fails to load some files, while these files are browsed directly in browser it's loading fine. No issues at all. What I am trying to do is create a pdf from html using a library called wkhtmltopdf programmatically using PHP.
The bucket I am trying to access is publicly accessible. Some of these files which are failing is also not the same ones as the previous, it keep's on changing every time. So I am not able to tag any doubts on it. When I checked regarding the limits of requests to an Amazon S3 bucket, can send up to 5500 requests per second. And here in my case am sending a request of 1600 that's all images files.
Below is my code.
<?php
set_time_limit(120);
require './aws-autoloader.php';
require './Aws/S3/S3Client.php';
require './Aws/Exception/AwsException.php';
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
?>
<html><body>
<?php
$response = $s3 ->listObjects(array('Bucket' =>"my-example-bucket"));
$data = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod laboriosam atque, consequuntur beatae fugiat in incidunt perspiciatis dolorem ipsum nam itaque animi nobis quam illum dolore. Nam nostrum maiores, ipsa.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa vero veniam sed ullam commodi! Accusantium, officia vitae, adipisci mollitia, blanditiis voluptates accusamus nam atque repellendus laborum, ullam vel eligendi esse?</p>';
foreach($response['Contents'] as $key => $value) {
$image = '';
$path = $value['Key'];
$image = "https://my-example-bucket.s3.amazonaws.com/$path";
$data.='<img src="'.$image.'" width="100">';
?>
<?php
}
$data.='</body>
</html>';
file_put_contents('C:\Users\Administrator\Demo\htdocs\test.html', $data);
exec('C:\"Program Files"\wkhtmltopdf\bin\wkhtmltopdf ./test.html ./test.pdf> C:\Users\Administrator\Downloads\my.txt 2>&1');
?>
</body></html>