如何在经典 ASP 中安排定期数据库清理任务?
我有一个经典 ASP 站点,需要按计划清空一些数据库表中的会话数据。该系统无法访问计划任务(它位于共享网络主机上,并使用 MySQL 服务器)
我正在考虑使用 global.asa
来触发如下事件:
Application_OnStart< /code> - 从数据库中删除所有会话数据
Application_OnEnd
- 删除所有会话数据Session_OnStart
- 创建用户会话Session_OnEnd
- 删除所有会话数据这与本届会议有关。
我有什么理由不应该在 global.asa
中创建数据库连接吗?这些将在这里创建和销毁,不会在会话或应用程序范围内共享。我将其视为每个用户运行这些管理任务两次(在会话开始和结束时)的一种方式,并且不会再次触发它们,相当于很少的数据库流量。
任何人都知道为什么这可能不好?有什么理由不连接到 global.asa
中的数据库吗?
如果有人认为上述想法是一个坏主意 - 您是否有任何其他想法关于如何定期清空这些表而不需要以下一项或多项:
- 计划任务
- 数据库计划任务
- 在每个页面的页面加载上运行代码(因此 < code>Session_OnStart 钩子)
Ta'
高级椰子
I have a Classic ASP site, that requires some database tables to be emptied out of session data on a schedule. This system doesn't have access to scheduled tasks (it's on a shared web host, and using MySQL server)
I was considering using global.asa
, to fire off events as such:
Application_OnStart
- delete all session data from databaseApplication_OnEnd
- delete all session dataSession_OnStart
- create a user' sessionSession_OnEnd
- delete all session data that relates to this session.
Is there any reason why I shouldn't create database connections in global.asa
? These will be created and destroyed here, no shared on session or application scope. I see it as a way of running these admin tasks twice per user (on session start and end) and not being fired again for them equating to very little database traffic.
Anyone have any ideas as to why this may be bad? Any reasons to not connect to a database in global.asa
?
If anyone thinks the above idea is a bad one - do you have any other thoughts as to how I can regularly empty these tables without one or more of:
- Scheduled task
- Database scheduled task
- Running the code on page load for every page (hence the
Session_OnStart
hooks)
Ta'
Senior Coconut
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以编写一个清空会话表的网页,并通过计划任务从外部框调用该页面。
You could write a web page that empties the session tables, and call that page from an external box via a scheduled task.
这取决于您的清理任务需要多长时间。由于在 Application_Start 运行时不会处理任何请求,因此它可能会阻塞一段时间。
此外,您无法保证在所有情况下都会调用 Application_End (或 Session_End)(当服务器关闭时,它可能不会被触发,或者某些灾难性故障可能会完全绕过这些事件)。
正如您所建议的,最好的方法是运行负责清理过时会话数据的计划任务。
It depends on how long your cleanup tasks will take. Since no request will be served while Application_Start is running, it may block for a while.
Moreover, you have no guarantee that Application_End (or Session_End) will be called in all cases (when the server is shut down it may not be fired, or some catastrophic failure may bypass these events entirely).
Best way would be, as you suggest, to run a scheduled task in charge of cleaning up stale session data.
我会在
Session_OnEnd
中对单个会话进行清理,并在Application_OnStart
中对所有会话进行清理。如果你的所有会话清理很慢,你可以做一件丑陋的事情,并将清理放在一个单独的 asp 文件中,你使用 XMLHTTP 类向该文件发出 http 请求,记住不要等待请求完成,因为它在运行Application_OnStart
中的所有代码之前,不会开始提供服务。I'd do cleanup for single session in
Session_OnEnd
and for ALL sessions inApplication_OnStart
. If your all-sessions-cleanup is slow, you can do a ugly thing and put that cleanup in a separate asp-file that you make a http-request to using the XMLHTTP class, remember to not wait for the request to complete as it won't begin being served before all code inApplication_OnStart
is run.如果您有稳定的流量,您可以在请求周期结束时搭载小任务。只需发出response.flush,然后执行数据库查询。当然,您需要编写自己的调度程序。另一种选择是创建一个单独的 asp 文件(tasklet),您可以在请求开始时使用服务器端、异步、xmlhttpreq 对其进行 ping 操作。这使得清理代码脱离了客户端请求周期并减少了延迟。
实际上,如果没有一些基于 webappr/api 的聪明的 appengine 可以按计划 ping 遗留的 tasklet/webhooks,我不会感到惊讶。如果没有,您可以自己写一个,选择是无穷无尽的:)
If you have consistent traffic you can piggyback small tasks at the end of a request cycle. Just issue a response.flush and then execute the db queries. Of course you need to write youre own scheduler. Another option is to create an seperate asp file (tasklet) which you ping using an serverside, async, xmlhttpreq at the start of the request. This keeps the cleanup code out of the clients request cycle and reduces latency.
Actually i woudn't be suprised if there isn't already some clever appengine based webappr/api that can ping youre legacy tasklet/webhooks on schedule. And if there isn't, you could write one youre self, the options are endless :)