douliang9057 2011-04-29 12:11
浏览 56
已采纳

在webapp中生成pdf,xls,png文件的正确方法

I have to generate some reports of various file type(excel, pdf, png), based on the inputs of a web application. The application is written in PHP on a apache webserver.

ATM, when users visit the reports section, they trigger the event which checks if there are submitted new data in the database and based on that info, the new report files are generated. This makes the user to wait until the files are generated (3-10seconds), what is not a good approach at all so I need any advice you can give me.

  • 写回答

1条回答 默认 最新

  • douchaqi3369 2011-04-29 12:26
    关注

    Of course it really depends on your application and your system, but typically what I do is I have a cron job that executes a PHP script to generate reports periodically. The output could be saved to the filesystem or in a database. This way my reports are only generated once (rather than each time a user tries to download them) AND they are only generated when needed (your script could check if it needs to generate a report based on whatever change criteria you have, or you could just set it up to generate whole new reports periodically). To keep it really simple just call your current web page with wget or curl, and create a new page on your webserver for downloading the saved reports.

    The only problem with this approach is users might download "stale" reports (data has changed but the reports haven't been updated). If this is really an issue another approach would be to keep a PHP script running in the background checking for modified data and generating reports as needed.

    Another approach is you could just continue generating reports when your users attempt to download them, but cache the results. Again using your own application-specific criteria you would check if the cached report is good enough for immediate download, or generate a new report and cache it. You could even combine this with the first approach by periodically generating new reports, but if a user attempts to download a report that is out of date immediately generate a new one (making the user wait 3-10 seconds).

    Ultimately it depends on your system and your application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题