Execute a program using global. asa

Source: Internet
Author: User
It is actually using the file "global. asa "! Many new ASP programmers want to know what this is? In fact, global. asa is an event driver, which contains four event processing processes: Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd.
When a page of an application on a website is accessed by a user for the first time, global. asa is loaded into the memory. When the application starts or ends, or the session starts or ends, you can add the script code to be executed.
With some tips, you can use the global. asa file to schedule tasks.
Here is an example: "Tracking the number of visitors to a website; when the number of visits reaches 100, the counter is reset to 0 and the code you prepared is executed ". Of course, you can adjust the maximum number of visits to 100 based on your needs.
The contents of global. asa are as follows:
<Script language = VBScript RUNAT = Server>
Sub Application_OnStart
Application ("SessionCount") = 0
End Sub
Sub Session_OnStart
Application. Lock
Application ("SessionCount") = Application ("SessionCount") + 1
Application. Unlock
If Application ("SessionCount")> 100 Then
Application. Lock
Application ("SessionCount") = 0
Application. Unlock
'Here you wocould put any code you need to run
'Do not surround the code with <%> tags
'For example you might run a database query that checks for expired accounts
End if
End Sub
Next, let's take a look at the execution of a task four times a day. You can store the date and time values in a text file and periodically check it. When the last six hours of time, write the new date and time to the text file and start the task you want to execute. You can change the value of "6" to execute more or less tasks.
Although the above method requires read and write permissions on text files before it can be correctly executed, it is still a very smart solution!
In this routine, the text file is checked once every 15 new visitors. Of course, you can adjust the value of "15" or set to check the text file whenever there are new visitors. However, such processing will undoubtedly increase the load on the site and waste server resources! In short, the inspection frequency is determined by yourself.
In this example, the validity of the date and time when a text file is written for the first time must be ensured. Otherwise, a running error occurs when the program reads a null value for the first time.
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.