进行 imagemagic 转换时避免 Flash 上传 30 秒超时?
我有一个使用 Flash 上传器 (swfuploader) 的 Web 应用程序,最近一位用户向我们指出了脚本挂起超过 30 秒时发生的错误。
我知道 Flash 文档提到在 30 秒没有响应后它将超时,所以我知道我需要在转换功能结束之前向浏览器发送一些数据。
截至目前,脚本上传文件,对其进行转换,如果它是多页 pdf,它会将参考子 png 保存到数据库,这对于大文件和小文件都可以正常工作,问题是在 30 页之后,它会挂起超过30秒。
提前致谢
I have a web app that uses a flash uploader (swfuploader) and recently a user pointed us to a bug that happens when the script hangs more than 30 seconds.
I know flash documentation mentions that after 30 seconds of no response it will timeout, so i know i need to send some data to the browser before my convert function ends.
As of now the script uploads the file, convert it, and if it is a multipage pdf it will save the reference children pngs to db, this works fine on big and small files, problem happens that after 30 pages it will hang for more than 30 seconds.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论是马克·罗宾斯的建议,还是您可能正在寻找这个 http:// php.net/manual/en/function.set-time-limit.php ,但您还需要检查服务器设置(它们也可能限制允许脚本运行的时间)。
让 PHP 异步工作将是一项艰巨的任务...我并不是说这将是一个完美的解决方案,但是,它是最容易实现的(至少在我看来):你可以开始“转换”作为一个单独的进程,获取它的 pid 并将该 pid 保存在会话/您知道与客户端关联的其他位置,然后让客户端轮询服务器以请求工作完成。一旦与 pid 关联的进程退出,客户端将需要接收保存到 imagemagic 转换内容的目录中的内容。
Either what Mark Robbins suggested, or you may be looking for this http://php.net/manual/en/function.set-time-limit.php , but you would also need to check the server settings (they might also limit the time the script is allowed to run).
Making PHP work asynchronously would be quite a task... I'm not saying this will be a perfect solution, but, it is the easiest to implement (at least so it seems to me): you could have start the "convert" as a separate process, get it's pid and save that pid in the session / other place you know to be associated with the client, and then have the client poll the server to ask for the work completion. Once the process associated with the pid exits, the client would need to receive what was saved into the directory where imagemagic converted things.
我认为你应该将整个事情构建为异步的,然后你就不必担心这个......对吗?
I think you should just build the whole thing to be asynch and then you dont have to worry about that... right?