开发者

How can I tell if my PHP S3 class putObjectFile() process has completed?

开发者 https://www.devze.com 2023-02-20 11:13 出处:网络
I am using PHP S3 class from undesigned to put uploaded audio files to开发者_高级运维 my amazon S3 bucket using the following syntax -

I am using PHP S3 class from undesigned to put uploaded audio files to开发者_高级运维 my amazon S3 bucket using the following syntax -

$s3 = new S3("awsAccessKey", "awsSecretKey");
$s3->putObjectFile(params);

then my code continues and uses CURL to call another server to retrieve the file in the S3 bucket and transcode the audio.

How can I tell when the putObject has completed successfully? what I am noticing is that the transcode process may fail, and I assume it is because the file has not completed being put to S3. I had assumed that the next line of code will not be executed until the putObject line has completed, do I need to wrap this in an if($s3->putObjectFile(...)) { } ?

thanks


you could use trycatch()

try
{
   $s3 = new S3("awsAccessKey", "awsSecretKey");
   $s3->putObjectFile(params);
}
catch(Exception $e)
{
   echo $e->getMessage();
}

in your function you would then throw an error with

throw new exception('error, could not complete, ....');

eg:

if(!dosomething) //if something failed
{
   throw new exception('error, could not complete, ....');
}

Using this it will stop executing code as soon as an exception is thrown. and then you just echo out or you could store it in a variable and then echo out wherever you want

0

精彩评论

暂无评论...
验证码 换一张
取 消