Skip to content

Instantly share code, notes, and snippets.

@rnjailamba
Last active June 9, 2019 03:59
Show Gist options
  • Save rnjailamba/fd4a87c68ef263ac967994bddbbd99c3 to your computer and use it in GitHub Desktop.
Save rnjailamba/fd4a87c68ef263ac967994bddbbd99c3 to your computer and use it in GitHub Desktop.
function saveResourcesToS3($file_Path, $content, $type){
$bucket = $this->aws_s3_bucket;
$key = 'resources'.'/'.$this->application_version . $file_Path;
$base_put_array = [
'Bucket' => $bucket,
'Key' => $key,
'Body' => $content,
'ACL' => 'public-read',
];
$result = null;
try {
//Create a S3Client
$s3Client = $this->S3Client;
if(!empty($type)){
if($type == 'css'){
$base_put_array['ContentType'] = 'text/css';
}
else if($type == 'js'){
$base_put_array['ContentType'] = 'text/javascript';
}
}
if(!empty($content)){
$result = $s3Client->putObject($base_put_array);
}
else{
$result = $s3Client->putObject([
'Bucket' => $bucket,
'Key' => $key,
'SourceFile' => $file_Path,
'ACL' => 'public-read',
]);
}
// unset($content);
// unset($base_put_array);
// unset($result);
// $this->garbageCollectionForce();
} catch (Exception $e) {
// $this->garbageCollectionForce();
echo $e->getMessage() . "\n";
sendMailToAll("IMPORTANT view.php saveResourcesToS3", "resources - css/js/view not getting saved to s3: " . $e->getMessage()." ");
die();
}
// echo $result;
// die();
}
function garbageCollectionForce(){
gc_collect_cycles();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment