I am making an auction website, which has an auto-bid system. This system lets people make biddings without having to be there.
My question is how to implement such a system. I have made the php files and everything is ready, I’ve made a html page which refreshes every second. It works, but I’m wondering if there’s a better solution.
The second option I tried was making an java application which opens the webpage every second. This consumes “a lot” of memory/CPU. Also, I think there is a memory leak somewhere.
I am running this application on a dedicated linux server with centOS and Plesk, so I am sure there are a lot of alternatives.
For example:
-
A cronjob that executes a php file every minute, where the php file loops for a minute with sleeps.
-
One php file that loops with 1 second sleeps.
-
One cronjob that executes and schedules another cronjob after a second.
-
MySQL scheduler, but I don’t know how to implement that, and I heard it locks the db for other writes.
-
I also heard about cli, perl, python scripts, but I am not familiar with any of them.
Please can someone with any knowledge of these options please shed some light for me on this subject. I am searching for a solution that is best suited in terms of speed and memory usage.
If someone has another alternative solution I would be glad to hear that also.
Every one second is such an small interval that cronjobs are a not an option, also i would strongly suggest against using a “webpage” as is, since performance is important just a script written for the CLI will do it.
What i would do is:
you should register that in a
database.
database for entries to be executed
at that moment.
Whoever, you need to be very careful of making the script sleep after each cycle or you will bring down your database.
On a side note, you really need it to be executed every second? In my mind auto-bids are triggered by events, i.e. someone bidding more than you while there’s 10 seconds left. That sound a lot nicer to implement and less resource intensive (and you can also use a daemon there, listening for auto-bids events, but that’s another story 🙂