如何在 PHP 中对事件进行排序以将文件上传到亚马逊 S3
我编写的一些 PHP 代码将文件上传到 S3,然后调用 EC2 实例对上传的文件执行操作,得到了不同的结果。
这是我做事的顺序 -
1) 使用 S3 类来放置文件
$result = s3 -> putObjectFile($uploadDIR, $bucket, $name, S3::ACL)
2) 检查 $result
if($result == "1") {
//file made it to s3
3) 使用 cURL 调用 EC2 实例并对 S3 中的文件执行操作
当我上传小视频时,我将其与视频文件一起使用文件它工作正常(例如 3MB),但对于较大的视频(例如 80MB),代码似乎没有通过步骤 1。文件被移动到 s3 好,但我的猜测是,一段时间后 PHP 放弃等待查看 $result == 1 因此不执行其余代码。
处理这样的事情最好的方法是什么? 如何检测文件是否已上传到 S3,然后在文件上传后运行一些代码?
I am getting varied results with some PHP code I have written to upload files to S3 then call an EC2 instance to perform actions on the uploaded file.
Here is the order I do things -
1) use S3 class to put file
$result = s3 -> putObjectFile($uploadDIR, $bucket, $name, S3::ACL)
2) check $result
if($result == "1") {
//file made it to s3
3) use cURL to call EC2 instance and perform action on file in S3
I am using this with video files, when I upload a small video file it works ok (eg 3MB) but for larger video (eg 80MB) the code doesnt seem to get past step 1. The file is moved to s3 ok but my guess is that after a while PHP gives up waiting to see if $result == 1 and so does not execute the rest of the code.
What is the best way to handle something like this? How can I detect that the file has been uploaded to S3 and then run some code when it has?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于大文件,上传它们所需的时间可能会高于脚本的 max_execution_time。
您可以只使用 set_time_limit() 函数,但对于网页来说这仍然可能不是一个好主意,因为脚本只会“挂”在那里,而没有任何用户反馈(输出到浏览器)。
这可能会更好:
For big files the time it takes to upload them will probably be higher than the script's max_execution_time.
You could just use the set_time_limit() function but it's still probably not a good idea for web pages as the script would just "hang" there without any user feedback (output to the browser).
This would probably be nicer: