Time between two consecutive queries

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
Ludus
Forum Newbie
Posts: 3
Joined: Tue May 19, 2009 5:07 am

Time between two consecutive queries

Post by Ludus »

Hi there,
I made a script to login at which furthermore shows the selected data from the table using a query as a scrolling text, based on the Iframe and Javascript options (such as a short info-service). From the login scripts run Javascript that call other small PHP script that produces a query and then Javascript displays the resulting code in layer login skripte. All works beautifully if you use as a normal user, but I am afraid of the possibility that a some user holds down the whole time F5 to refresh page and so overloaded webserver and service crashes. 8O Therefore I would like to know how to skip making a query if the previous query was less than 10 seconds, something like a flood prevention or prevention of multiple consecutive Search queries on some forums if the interval is less than a defined time. Thank you.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Time between two consecutive queries

Post by AbraCadaver »

You could start a session and each time the page loads to run the query you check the time against the time var you set in the session and see if it has been over 10 seconds. If so then run the query and update the session var with the new time, if not don't run the query.

However I don't think these reloads will really cause a problem.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Time between two consecutive queries

Post by Darhazer »

Cache the results from the query (in a file or in memcached). Use cache expiration (if you cache in a file, check the modification timestamp of the file)
Post Reply