简体   繁体   English

在单个页面加载中传输(相当)大量的数据

[英]Transferring a (fairly) large amount of data across a single page load

I have an application that generates an array of statistics based on a greyhounds racing history. 我有一个应用程序,可以根据赛狗的比赛历史生成一系列统计信息。 This array is then used to generate a table which is then output to the browser. 然后,此数组用于生成表,然后将其输出到浏览器。 I am currently working on creating a function that will generate an excel download based on these statistics. 我目前正在创建一个函数,该函数将基于这些统计信息生成excel下载。 However, this excel download will only be available after the original processing has been completed. 但是,此excel下载仅在原始处理完成后才可用。 Let me explain. 让我解释。

  1. The user clicks on a race name 用户单击种族名称
  2. The data for that race is then processed and displayed in a table. 然后处理该种族的数据并将其显示在表格中。
  3. Underneath the table is a link for an excel download. 表格下方是一个excel下载链接。

However, this is where I get stuck. 但是,这就是我遇到的问题。 The excel download exists within another method within the same controller like so... excel下载存在于同一控制器内的另一种方法中,例如...

function view($race_id) {
    //Process race data and place in $stats
    //Output table & excel link
}

function view_excel($race_id) {
    //Process race data <- I don't want it to have to process all over again!
    //Output excel sheet
}

As you can see, the data has already been processed in the "view" method so it seems like a massive waste of resources having it processed again in the "view_excel" method. 如您所见,数据已经通过“ view”方法进行了处理,因此在“ view_excel”方法中再次进行处理似乎浪费了很多资源。

Therefore, I need a method of transferring $stats over to the excel method when the link is clicked to prevent it having to be reproduced. 因此,当单击链接以防止必须复制时,我需要一种将$ stats转移到excel方法的方法。 The only methods I can think of are as follows. 我能想到的唯一方法如下。

  • Transferring $stats over to the excel method using a session flash 使用会话闪存将$ stats转移到excel方法
    • The variable may end up being too big for a session variable. 对于会话变量,变量可能最终太大。 Also, if for some reason the excel method is refreshed, the variable will be lost. 同样,如果由于某种原因刷新了excel方法,该变量也会丢失。
  • Transferring $stats over to the excel method using an ordinary session variable 使用普通会话变量将$ stats转移到excel方法
    • As above, the variable may end up being too big for a session variable. 如上所述,对于会话变量,变量可能最终太大。 This has the benefit that it wont be lost on a page refresh but I'm not sure how I would go about destroying old session variables, especially if the user it processing alot of races in a short period of time. 这样的好处是它不会在页面刷新时丢失,但是我不确定如何销毁旧的会话变量,特别是如果用户在短时间内处理大量比赛时。
  • Storing $stats in a database and retrieving it in the excel method 将$ stats存储在数据库中并以excel方法进行检索
    • This seems like the most viable method. 这似乎是最可行的方法。 However, it seems like a lot of effort to just transfer one variable across. 但是,似乎只需要跨一个变量就可以进行大量的工作。 Also, I would have to implement some sort of cron job to remove old database entries. 另外,我将必须实施某种cron作业才能删除旧的数据库条目。

An example of $stats : $ stats的示例:

Array
(
    [1] => Array
        (
            [fcalc7] => 
            [avgcalc7] => 
            [avgcalc3] => 86.15
            [sumpos7] => 
            [sumpos3] => 9
            [sumfin7] => 
            [sumfin3] => 8
            [total_wins] => 0
            [percent_wins] => 0
            [total_processed] => 4
            [total_races] => 5
        )

    [2] => Array
        (
            [fcalc7] => 28.58
            [avgcalc7] => 16.41
            [avgcalc3] => 28.70
            [sumpos7] => 18
            [sumpos3] => 5
            [sumfin7] => 23
            [sumfin3] => 7
            [total_wins] => 0
            [percent_wins] => 0
            [total_processed] => 7
            [total_races] => 46
        )

    [3] => Array
        (
            [fcalc7] => 28.47
            [avgcalc7] => 16.42
            [avgcalc3] => 28.78
            [sumpos7] => 28
            [sumpos3] => 11
            [sumfin7] => 21
            [sumfin3] => 10
            [total_wins] => 0
            [percent_wins] => 0
            [total_processed] => 7
            [total_races] => 63
        )
)

Would be great to hear your ideas. 听到您的想法会很棒。

Dan

You could serialize the array into a file in sys_get_temp_dir() with a data-dependet file name. 您可以将数组序列化为 sys_get_temp_dir()中具有数据相关文件名的文件。 The only problem left is cleaning up old files. 剩下的唯一问题是清理旧文件。

Putting it into the database is also possible as you said, and deleting old data is easier than on the file system if you track the creation time. 如您所说,也可以将其放入数据库中;如果您跟踪创建时间,则删除旧数据比在文件系统上更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM