PHP code example of renoki-co / laravel-ec2-metadata
1. Go to this page and download the library: Download renoki-co/laravel-ec2-metadata library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
renoki-co / laravel-ec2-metadata example snippets
use Carbon\Carbon;
use RenokiCo\Ec2Metadata\Ec2Metadata;
if ($termination = Ec2Metadata::terminationNotice()) {
// The instance is terminating...
$secondsRemaining = Carbon::parse($termination['time'])->diffInSeconds(now());
echo "The instance is terminating in {$secondsRemaining} seconds.";
}
use RenokiCo\Ec2Metadata\Ec2Metadata;
Ec2Metadata::version('2016-09-02');
use RenokiCo\Ec2Metadata\Ec2Metadata;
$kernelId = Ec2Metadata::get('kernel-id');
class Ec2Metadata
{
public static function terminationNotice(): array
{
// Expected response is {"action": "terminate", "time": "2017-09-18T08:22:00Z"}
return static::getJson('/spot/instance-action');
}
}
use RenokiCo\Ec2Metadata\Ec2Metadata;
Ec2Metadata::macro('kernelId', function () {
return static::get('kernel-id');
});
$kernelId = Ec2Metadata::kernelId();