Question

I was thinking it be cool to have a simple matchmaker code in php. The idea is the app connect to the server or a specific webpage, the webpage takes it IP and the last X ips and prints it on page (his first)

problem is what happens when 5 ppl hit the page the same second. How do i handle it? i cant use global/shared memory? so i would need to write the IPs to a file and read/writing them everytime (10x the same second) would be bad? i guess its ok to be slow but i want this to be optimized if possible.

Is it better to store in a mysql db?

Was it helpful?

Solution

I would suggest using APC to memcache the information in memory.. This would only work for 1 server. With multiple servers, you should look at something like memCacheD.

OTHER TIPS

I'm not quite sure why you'd bother doing this, except as a learning exercise, but you're basically going to be persisting the information somewhere, if only for a relatively short time, and you need reasonable transactional semantics.

Probably the simplest option would be to opt for a database; MySQL would be fine, and if you really don't need to store the data for a particularly long time, then you might as well use an in-memory table - use the MEMORY (or HEAP) storage engine for this. Using a database in this manner means you don't have to worry too much about conflicting concurrent writes, etc.

You don't need to write the IP of the requestor in a file - Apache is already doing it for you. Just grep the last lines of the /var/log/httpd/access_log file (if you're on linux) and you'll find the info you need about the last requests received by the server - IP, referer, URL. And they're serialized.

bye!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top