Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. function saveResourcesToS3($file_Path, $content, $type){
  2. $bucket = $this->aws_s3_bucket;
  3. $key = 'resources'.'/'.$this->application_version . $file_Path;
  4. $base_put_array = [
  5. 'Bucket' => $bucket,
  6. 'Key' => $key,
  7. 'Body' => $content,
  8. 'ACL' => 'public-read',
  9.  
  10. ];
  11. $result = null;
  12.  
  13. try {
  14. //Create a S3Client
  15. $s3Client = $this->S3Client;
  16. if(!empty($type)){
  17. if($type == 'css'){
  18. $base_put_array['ContentType'] = 'text/css';
  19. }
  20. else if($type == 'js'){
  21. $base_put_array['ContentType'] = 'text/javascript';
  22. }
  23. }
  24. if(!empty($content)){
  25. $result = $s3Client->putObject($base_put_array);
  26. }
  27. else{
  28. $result = $s3Client->putObject([
  29. 'Bucket' => $bucket,
  30. 'Key' => $key,
  31. 'SourceFile' => $file_Path,
  32. 'ACL' => 'public-read',
  33. ]);
  34. }
  35. // unset($content);
  36. // unset($base_put_array);
  37. // unset($result);
  38. // $this->garbageCollectionForce();
  39.  
  40. } catch (Exception $e) {
  41. // $this->garbageCollectionForce();
  42. echo $e->getMessage() . "\n";
  43. sendMailToAll("IMPORTANT view.php saveResourcesToS3", "resources - css/js/view not getting saved to s3: " . $e->getMessage()." ");
  44. die();
  45. }
  46. // echo $result;
  47. // die();
  48. }
  49.  
  50. function garbageCollectionForce(){
  51. gc_collect_cycles();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement