Forum Moderators: coopster

Message Too Old, No Replies

Most efficient way to mimic a superglobal variable

Keeping Amazon under one second

         

suidas

7:30 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



My website allows users to search Amazon. Amazon limits me to one request/second. The site needs to keep track of when the last request was sent and, if it was less than one second ago, wait a moment before sending the next.

What is the best way to handle this? I could save and read a single field from a single row of a MySQL table. Is there a better way? If there isn't does anyone have any advice about the fastest way to do the MySQL?

vdoyl

9:06 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



It will be faster to use file functions for the purpose.

Write the last search timestamp in a file, then on the next search read that file and then write the new search timestamp and so on.

It is faster in times compared to mysql queries.

Also, when using amazon it is good idea to keep some cache of the returned results - this will save you bandwidth and search request to amazon.

suidas

9:16 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



Actually, might it not be faster to write a file and use the file's own timestamp instead of going to the trouble of actually *reading* it? Anyway, I could profile that too.

coopster

10:19 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may also consider flock() [php.net] to avoid collisions with 50 users running requests in the same second.