[英]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.
让我解释。
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.
我能想到的唯一方法如下。
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.